0

I am trying to set up the Apache server which comes with OS X Mavericks with vhosts so that a domain name resolves to my user level document webroot. I have followed this tutorial which guided me through setting up the apache server with php:

http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-9-mavericks/

as well as this one which guided me through setting up the vhosts:

http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-9-mavericks-osx-10-8-mountain-lion/

Following these tutorials, if I type localhost in my browser it correctly resolves to the system level root (/Library/WebServer/Documents/ folder). If I use localhost/~myusername it correctly resolves to my user level root (/users/myusername/Sites/).

However, whenever I navigate to my domain, I get redirected to the system level root rather than my user level root.

My vhosts file reads as follows:

<VirtualHost *:80>
        ServerName localhost
        DocumentRoot /Library/WebServer/Documents/
</VirtualHost>

<VirtualHost *:80>
        ServerName mydomain.com
        ServerAlias www.mydomain.com
        DocumentRoot "/Users/myusername/Sites/mydomain"
        <Directory "/Users/myusername/Sites/mydomain">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Any ideas?

Ben Thompson
  • 4,743
  • 7
  • 35
  • 52

3 Answers3

0

Have you enabled Virtualhosts?

NameVirtualHost *:80

And included your vhosts directory

Include <path>/vhosts/*

On a Macbook, you may need to include /private/ at the beginning of any absolute path, so that Apache can read it correctly off the file system.

Garreth McDaid
  • 2,427
  • 22
  • 34
  • I think so - to be clear, I have uncommented the line `Include /private/etc/apache2/extra/httpd-vhosts.conf` in httpd.conf. I am reasonably confident this bit is working because when i navigate to my domain, it does bring up a webpage (so is correctly identifying that i am accessing a virtual host) it just redirects to the system level root rather than the user level root – Ben Thompson Mar 10 '14 at 11:13
  • But "DocumentRoot /Library/WebServer/Documents/" is probably the system level default, so VirtualHosts may not be enabled. Do you have "NameVirtualHost *:80" in your httpd.conf file? – Garreth McDaid Mar 10 '14 at 12:57
  • No - I have that in my httpd-vhosts.conf file. Does it need to be in the httpd.conf file as well? – Ben Thompson Mar 10 '14 at 18:35
  • "AH00548: NameVirtualHost has no effect and will be removed in the next release" -- according to the version of Apache in OS X 10.10 (Apache/2.4.9) – Owen Feb 05 '15 at 07:19
0

For others who have the same problem...

It was frustratingly simple - I had missed the "" around the localhost directory.

How annoying!

Ben Thompson
  • 4,743
  • 7
  • 35
  • 52
0

Try starting apache manually with the -S option to see what the problem might be:

/usr/sbin/httpd -S
Owen
  • 3,063
  • 5
  • 30
  • 26