VirtualHosts does not work on Mac OS 10.7 VirtualHosts does not work on Mac OS 10.7 apache apache

VirtualHosts does not work on Mac OS 10.7


apachectl has an option -S to check vhost.conf file syntax. You can find these lines in vhosts.conf file.

> # You may use the command line option '-S' to verify your virtual host> # configuration.

So, when you run

sh-3.2# apachectl -S

if you get Syntax OK result it means that there is no problem in your vhosts.conf file.

httpd: VirtualHost configuration:wildcard NameVirtualHosts and _default_ servers:*:80                   is a NameVirtualHost         default server zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)         port 80 namevhost zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)         port 80 namevhost yy.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:35)Syntax OK

If conf file has any problem it will tell you error line(s) like

sh-3.2# apachectl -SSyntax error on line 33 of /private/etc/apache2/extra/httpd-vhosts.conf:CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)

make sure that your vhosts.conf file has true configuration.


I had the exact same problem using OS X Lion. I fixed it by adding "::1 myhost.dev" to /etc/hosts:

127.0.0.1 myhost.dev::1 myhost.dev

Incidentally, the ::1 also fixes a bug that makes page loading very slow on virtual hosts served from the Mac.


Are you using an HTTP proxy? If so, make an exception for myApplication.dev and myApplication2.dev.

What I meant was that the problem "server mot found" means that your browser cannot find the ip adresses of the hosts "myapplication.dev". This may be because you're using an http proxy, possibly one configured by your hosting company. In any case, you don't even reach the server, so you never get to try the virtual host configuration at all.

To just try the virtual host configuration, you can use telnet in a Terminal window and talk HTTP directly to the server, like this:

yourmacbox:~ yourname$ telnet 127.0.0.1 80

You should see the following text:

Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.

Then you type

GET / HTTP/1.0Host: myApplication.dev

Now, hopefully you should see some response from your web server. This shows that once you can connect to it, the virtual hosts things works.