Question

I'm trying to get the Apache server that comes with OS X to work for my local website. No matter what I change the file httpd-vhosts.conf to, when I run httpd -S in Terminal it says my virtual host syntax is OK. I typed in a bunch of random characters into the file, restarted Apache, and it still says my configuration is OK.

First I edited /private/etc/hosts and added this line underneath 127.0.0.1 localhost:

127.0.0.1   mysite

Then I edited /private/etc/apache2/httpd.conf. I uncommented this line:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

I also uncommented the PHP5 line to enable PHP.

Next I edited /private/etc/apache2/extra/httpd-vhosts.conf and set up my virtual hosts. After restarting apache, my virtual hosts were not working and running httpd -S said my virtual hosts syntax was OK. No erros in the Apache error log. This is what the httpd-vhosts.conf file contained:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Users/Gavin/Web"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/Gavin/Web/mysite/public_html"
    ServerName mysite
</VirtualHost>

No matter what I did, my virtual hosts would not work. So I tried changing httpd-vhosts.conf to this:

NameVirtualHost *:80

<VirtualHost @*^#*&^#$>
    (#*&#*$&@(*UOSKSFLKSFJLJF##*(&
</VirtualHost>

I restarted Apache using sudo apachectl restart and then ran apachectl -S and it says:

httpd: Could not reliably determine the server's fully qualified domain name, using Gavins-MacBook-Pro.local for ServerName
VirtualHost configuration:
Syntax OK

Obviously my httpd-vhosts.conf file is not OK, so which file is it loading? In Terminal I ran httpd -V|grep SERVER_CONFIG_FILE and it returned:

-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

That's obviously the correct httpd.conf file, so what's going on here? Any ideas?

Was it helpful?

Solution 2

After trying everything, and nothing working, I downloaded an app for managing vhosts. It's expensive but has a free 14 day trial (just google search for it and you'll find it). Anyway, the app changed my httpd-vhosts.conf file to this and now it's working:

NameVirtualHost *:80

<Directory "/Users/Gavin/Web/">
Allow From All
AllowOverride All
Options +Indexes
</Directory>
<VirtualHost *:80>
    ServerName "localhost"
    DocumentRoot "/Users/Gavin/Web"
</VirtualHost>

<Directory "/Users/Gavin/Web/mysite/public_html/">
Allow From All
AllowOverride All
Options +Indexes
</Directory>
<VirtualHost *:80>
    ServerName "mysite"
    DocumentRoot "/Users/Gavin/Web/mysite/public_html"
</VirtualHost>

I read 20+ tutorials on setting up vhosts on OS X and none of them worked. This tool worked for me.

OTHER TIPS

Your should look forward '/private/etc/apache2/users/' folder. There is a special (Your username).conf where you can add your virtual hosts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top