tester
tester

Reputation: 3987

VirtualHosts does not work on Mac OS 10.7

I want to create VirtualHosts on Mac OS 10.7 and therefore I edited the /etc/apache2/httpd.conf. I uncommented the line "Include /private/etc/apache2/extra/httpd-vhosts.conf" to include the virtual hosts. In the file /private/etc/apache2/extra/httpd-vhosts.conf I wrote the following:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/var/www"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/someFolder"
    ServerName myApplication.dev
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/someOhterFolder"
    ServerName myApplication2.dev
</VirtualHost>

There were two example virtual hosts before which I deleted. In my /etc/hosts file I added the following:

127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev

I restarted my Apache and typed myApplication.dev and myApplication2.dev in the browser but I get an error "server not found" and it makes www.myApplication.dev in the browser (the same for myApplication2.dev).

Did I forget something to configure? I activated PHP in httpd.conf, mysql is installed also, but that has nothing to do with virtual hosts, I think. Thanks for your help!

Upvotes: 4

Views: 8395

Answers (4)

cyb0k
cyb0k

Reputation: 2738

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 -S
Syntax 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.

Upvotes: 8

orourkedd
orourkedd

Reputation: 6421

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.

Upvotes: 6

Shyam Habarakada
Shyam Habarakada

Reputation: 15795

I had the same problem, and noticed that the ServerRoot "/usr" was set as shown and incorrectly after the 10.7 upgrade. The httpd.conf file was still under /etc/apache2, but this setting in it was pointing to the wrong place. Once I had fixed that by changing to ServerRoot "/etc/apache2", all my previous virtual host configuration got picked up properly.

I also had to re-enable virtual hosts by uncommenting line 477 as mentioned here http://brettterpstra.com/fixing-virtual-hosts-and-web-sharing-in-mountain-lion/ That didn't quite kick in until I had fixed the path issue above.

Upvotes: 2

Jenny D
Jenny D

Reputation: 1245

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

Upvotes: 2

Related Questions