1

I got a strange problem trying to define multiple virtual hosts in Apache. This is my code for httpd.conf file:

<VirtualHost *:8888> ServerName site1.local DocumentRoot /Applications/MAMP/htdocs/site1/public <Directory /Applications/MAMP/htdocs/site1/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:8888> ServerName site2.local DocumentRoot /Applications/MAMP/htdocs/site2/public <Directory /Applications/MAMP/htdocs/site2/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

When I try to access "site2.local" in browser, I'm redirected to "site1.local". This will happen to all VirtualHost definitions that I insert below in the httpd.conf file. When I want to access "site2.local" or any other, I need to put its VirtualHost definition on the top (as the first one). So, I assume that Apache is only executing correctly the first VirtualHost.

Also, another problem: if I try to access any file of project in my htdocs folder which is not defined in VirtualHost, I will get a message "Forbidden, You don't have permission to access /project/ on this server." If I want to access any of these projects, I need to remove all VirtualHost definitions in httpd.conf file.

What I am doing wrong?

In my case, these (defined in VirtualHost) are PHP projects w/ Zend Framework. I'm using MacOSX.

Thank you

1 Answer 1

0

you are missing

NameVirtualHost *:8888 

and

<VirtualHost _default_:8888> DocumentRoot /www/default </VirtualHost> 

For more information about the apache default virtual host, you can read this online doc

http://httpd.apache.org/docs/2.2/vhosts/examples.html 
9
  • You don't actually need a default virtualhost, unless you really want to... normally if Apache gets a request for an unknown servername it will simply serve the first loaded virtualhost. Commented May 14, 2014 at 7:56
  • @stoned how do you solve the problem? Commented May 14, 2014 at 17:45
  • It's not really a problem, sorry if it looked like that I meant so. I just pointed out that the default virtualhost isn't mandatory/needed to have the resut that was asked for. Commented May 14, 2014 at 22:15
  • @stoned :) ok, but i would like to know, how can i have the result of that was asked for,without using the default virtual host Commented May 15, 2014 at 8:31
  • 1
    NameVirtualHost *:8888 (together with a Listen 8888 of course) should be enough to make everything work as asked in the first part of the question. Problem is, the guy seems not to be taking much care of this question and as such we can't assess if that was really the problem, or if it should be looked for elsewhere. Commented May 15, 2014 at 13:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.