Solved

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

Posted on 2011-09-22
9
273 Views
Last Modified: 2013-11-05
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.
0
Comment
Question by:skiabox
  • 5
  • 4
9 Comments
 

Author Comment

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

Expert Comment

by:Papertrip
ID: 36581671
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

0
 

Author Comment

by:skiabox
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
</IfModule>

Open in new window


Should I change this code?
0
 
LVL 21

Expert Comment

by:Papertrip
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.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 21

Expert Comment

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

Author Comment

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

Expert Comment

by:Papertrip
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/mod_dir.so

Open in new window

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

Author Comment

by:skiabox
ID: 36582724
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
0
 
LVL 21

Accepted Solution

by:
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 mod_dir.so 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/mod_dir.so
-rwxr-xr-x. 1 root root 10416 Jul  7 03:31 modules/mod_dir.so*

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.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now