Link to home
Start Free TrialLog in
Avatar of skiabox
skiabox

asked on

How to config apache virtual host with automatic load of index.php

I have created a virtual host (www.myhost.org) that points to my machine (I have added 127.0.0.1 www.myhost.org to /etc/hosts).
How can I configure it so that it points to index.php ?
Now I have to write www.myhost.org/index.php
If I write www.myhost.org I get a simpe 'It Works!'

Thank you.
Avatar of skiabox
skiabox

ASKER

My operating system is Mac Os Lion.
I have added 127.0.0.1 www.myhost.org to /etc/hosts
Nothing except localhost and/or localhost.localdomain should be in your hosts file for 127.0.0.1.
How can I configure it so that it points to index.php ?
You need to add index.php to the DirectoryIndex.  This can be done in the main httpd.conf, in the virtualhost config block, per directory, or in .htaccess.

DirectoryIndex index.php

Open in new window

Avatar of skiabox

ASKER

I have the following code in my httpd.conf file :

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

Open in new window


Should I change this code?
That will change it globally for all virtual servers.  Unless you have a specific need NOT to let particular vhosts have that for their DirectoryIndex, do the global change so that you don't have to create a separate DirectoryIndex for each vhost.
*correction -- that will change DirectoryIndex for all of your hosts, not just virtual.  Just wanted to make that clear.
Avatar of skiabox

ASKER

But that code is not working.
Probably the ifmodule never execute.
That is definitely possible, but I would be surprised if that were the case.

Let's see if apache is loading that module:
[root@broken ~]# grep mod_dir /etc/httpd/conf/httpd.conf
LoadModule dir_module modules/mod_dir.so

Open in new window

If it's commented out, uncomment and restart apache.
Avatar of skiabox

ASKER

LoadModule dir_module libexec/apache2/mod_dir.so

exists and it is uncommented.

I wonder about that libexec directory.
The proper directory (at least in my system) is /etc/apache2
ASKER CERTIFIED SOLUTION
Avatar of Papertrip
Papertrip
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial