Apache2 index.php

Asked by John Lyons on 2010-10-21


Can you please tell me where to configure Apache2 to process index.php in preference to index.html, when I browse to http://localhost/ ?


Question information

English Edit question
Ubuntu apache2 Edit question
No assignee Edit question
Solved by:
John Lyons
Last query:
Last reply:
François Tissandier (baloo) said : #1

How about the DirectoryIndex option in the httpd.conf file?
More info there: http://httpd.apache.org/docs/2.0/mod/mod_dir.html

John Lyons (lyonsjrl) said : #2

Thanks Francois

I will read the info you suggest. I expected to find a httpd.conf file, but cannot locate one. The Apache2.conf does not contain a reference to DirectoryIndex and I was not sure whether to add one, or even if this is the correct file.

François Tissandier (baloo) said : #3

You can open a terminal, then type

"locate httpd.conf"
If this file does exist in your system, you will find it.

It should be in /etc/apache2/

John Lyons (lyonsjrl) said : #4

I do have a httpd.conf file in /etc/apache2 but is zero bytes. I saw this but thought that I may have created this with an editor when I was looking to open a file of that name. If I browse to http://localhost/ it loads my index.html file. I need to browse to http://localhost/index.php to get that file.

So Apache appears to be working, which made me think that Apache is not using the httpd.conf anyway. As I said I will work through the documentation and if need be purge Apache and re-install. As you may have gathered I am an Linux newbie. Thanks for your help.

François Tissandier (baloo) said : #5

John, what do you have in the /etc/apache2 folder then? I'm surprised
that you do not have this file. Are you sure it's apache2 you are
using and not a 1.x version ? Thanks !

John Lyons (lyonsjrl) said : #6

Sorry Francois - I have been busy on other things.

-rw-r--r-- 1 root root 8113 2010-08-19 13:19 apache2.conf
drwxr-xr-x 2 root root 4096 2010-10-25 19:59 conf.d
-rw-r--r-- 1 root root 725 2010-08-19 13:19 envvars
-rw-r--r-- 1 root root 0 2010-10-06 15:04 httpd.conf
-rw-r--r-- 1 root root 31063 2010-08-19 13:19 magic
drwxr-xr-x 2 root root 4096 2010-10-06 15:04 mods-available
drwxr-xr-x 2 root root 4096 2010-10-06 15:04 mods-enabled
-rw-r--r-- 1 root root 750 2010-08-19 13:19 ports.conf
drwxr-xr-x 2 root root 4096 2010-10-19 19:09 sites-available
drwxr-xr-x 2 root root 4096 2010-10-20 19:28 sites-enabled

Maybe I clobbered httpd.conf. If so I am surprised Apache still works.

François Tissandier (baloo) said : #7

Mine just includes one line, so it's maybe fine if it's empty... But you can probably add the DirectoryIndex directive in this file, restart Apache, and see if it's working.

Try to add this line:

DirectoryIndex index.php index.html

John Lyons (lyonsjrl) said : #8

Thanks Francois.

Lost my hard drive last night so it maybe a couple of days before I can get set up again.

John Lyons (lyonsjrl) said : #9


Got my system sorted. I am running Ubuntu as a virtual machine with the host of Windows XP. XP was corrupted but I managed to salvage my data using Knoppix. Anyway I eventually stumbled upon placing the directive:

DirectoryIndex index.php index.html

in /etc/apache2/sites-available/wtt which is my virtualhost.

That works. When I browse to http://localhost/ the index-php file is loaded.

Thanks for you help.

François Tissandier (baloo) said : #10

Great ! You are welcome !