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

Posted on 2011-09-22
Last Modified: 2013-11-05
I have created a virtual host ( that points to my machine (I have added to /etc/hosts).
How can I configure it so that it points to index.php ?
Now I have to write
If I write I get a simpe 'It Works!'

Thank you.
Question by:skiabox
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4

Author Comment

ID: 36581618
My operating system is Mac Os Lion.
LVL 21

Expert Comment

ID: 36581671
I have added to /etc/hosts
Nothing except localhost and/or localhost.localdomain should be in your hosts file for
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


Author Comment

ID: 36582512
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

Open in new window

Should I change this code?
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

LVL 21

Expert Comment

ID: 36582555
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.
LVL 21

Expert Comment

ID: 36582571
*correction -- that will change DirectoryIndex for all of your hosts, not just virtual.  Just wanted to make that clear.

Author Comment

ID: 36582593
But that code is not working.
Probably the ifmodule never execute.
LVL 21

Expert Comment

ID: 36582632
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/

Open in new window

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

Author Comment

ID: 36582724
LoadModule dir_module libexec/apache2/

exists and it is uncommented.

I wonder about that libexec directory.
The proper directory (at least in my system) is /etc/apache2
LVL 21

Accepted Solution

Papertrip earned 500 total points
ID: 36583021
That is probably the ServerRoot, so you are on the right track.  Go into your ServerRoot and do an ls, you should see a symlink to the actual modules directory.

On a related note, if that module did not exist but was defined in httpd.conf, you would see errors for it in your error_log.  You can either remove the IfModule directive and leave just the DirectoryIndex, or you can try pointing IfModule to instead of dir_module.

[root@broken ~]# grep '^ServerRoot' /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
[root@broken ~]# cd /etc/httpd
[root@broken httpd]# ls -l
total 16
drwxr-xr-x.  4 root root 4096 Sep 18 02:45 ./
drwxr-xr-x. 67 root root 4096 Sep 22 03:27 ../
drwxr-xr-x.  2 root root 4096 Sep 18 02:45 conf/
drwxr-xr-x.  2 root root 4096 Sep 20 02:13 conf.d/
lrwxrwxrwx.  1 root root   19 Sep 18 02:45 logs -> ../../var/log/httpd/
lrwxrwxrwx.  1 root root   29 Sep 18 02:45 modules -> ../../usr/lib64/httpd/modules/
lrwxrwxrwx.  1 root root   19 Sep 18 02:45 run -> ../../var/run/httpd/
[root@broken httpd]# ls -l modules/
-rwxr-xr-x. 1 root root 10416 Jul  7 03:31 modules/*

Open in new window

You may also have an AllowOverride directive set someplace -- look for that in your conf files and .htaccess if you are using one.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Website being blocked? 3 146
phpPgAdmin problem 14 282
Do you know any Office editor web for IIS or Apache web server)??? 10 110
How to fix Dual Server Conflict GitLab vs Apache2 3 60
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question