Question

I am trying to set up an Apache vhost on Mavericks, something that I was able to do easily on 10.6.8. I am using the default Apache that is preinstalled on a fresh install of OS X 10.9.2

$ sudo apachectl start
org.apache.httpd: Already loaded

$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.053 ms

But when I navigate to either http://localhost or http://127.0.0.1 on any of my 3 browsers, I'm told I can't connect, instead of seeing Apache's "It Works!" message. (On Chrome I see "Oops! Google Chrome could not connect to localhost")

I also tried adding a vhost:

  1. Uncommented Include /etc/apache2/extra/httpd-vhosts.conf in /private/var/appache2/httpd.conf
  2. Added 127.0.0.1 test.local to /etc/hosts
  3. Added the following to /etc/apache2/extra/http2-vhosts.conf

    <VirtualHost *:80>
     ServerName test.local
     DocumentRoot /Users/me/test
     <Directory /Users/me/test>
       AllowOverride all
       Options -MultiViews
     </Directory>
    </VirtualHost>
    
  4. Restarted Apache

    $ apachectl -t
    Syntax OK
    $ sudo apachectl graceful
    $ ping test.local
    PING test.local (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.040 ms
    

...but again, nothing when I navigate to http://test.local

Any thoughts? Does this have something to do with Mavericks' new "Web Sharing" preference, which you have to download separately, or something?


Edit:

Figured it out! I had to modify the main httpd.conf Directory options to AllowOverride All and Allow from All, as per this tutorial. The conf file that comes with Mavericks has this turned off. If I had looked at my original conf file on my old machine, I would have noticed the difference.

The other thing that was messing me up is that if I have

ErrorLog "/Users/me/error.log"

in my VirtualHost definition, I get "Chrome can't connect", even though Apache tells me the syntax is fine. Removing it resolves the problem.

Thanks all!

Was it helpful?

Solution

Check /var/log/apache2/error_log or /var/log/system.log. You can also try to flush the DNS cache by running sudo killall -HUP mDNSResponder. See http://support.apple.com/kb/ht5343.

Just running sudo apachectl start makes http://localhost show the "It works!" page for me in a 10.9 VM.

Saving

<Directory "/Users/username/Sites/">
  Options Indexes Multiviews
  AllowOverride AuthConfig Limit
  Order allow,deny
  Allow from all
</Directory>

as /etc/apache2/users/username.conf and running sudo apachectl restart makes http://localhost/~username/ point to ~/Sites/.

Uncommenting Include /private/etc/apache2/extra/httpd-vhosts.conf in /etc/apache2/httpd.conf, adding 127.0.0.1 test.dev to /etc/hosts, adding

<VirtualHost *:80>
  DocumentRoot "/Users/username/Sites/test"
  ServerName test.dev
</VirtualHost>

to /etc/apache2/extra/httpd-vhosts.conf, and running sudo apachectl restart makes http://test.dev point to ~/Sites/test/.

OTHER TIPS

First of all, did you flush your DNS cache after changing the hosts file? Run dscacheutil -flushcache in Terminal.

Second, you can run apachectl -S to check your apache2 config. Correct any errors and restart apache again.

Third, check the permissions on your /Users/me/test directory. Chmod the permissions on that directory to 775 or even 777 to see if that helps.

I've updated to Mavericks from Snow Leopard and my apache gave me hard time right away. After banging my head for two straight nights, reading everything about configuring Apache under Mavericks and seeing no progress on it whatsoever – I've been having "It works" message for every virtual host which was previously configured with SL and at some point even that stopped working – I've found that if you swap your old httpd.conf-previous with the newly generated httpd.conf, you should comment out LoadModule bonjour_module libexec/apache2/mod_bonjour.so, too. apachectl start (or restart) doesn't throw any errors, but it actually doesn't like this module at all. So comment this one line out.

I guess, the lesson is to triple-check every directive in the config. And bang your head less, too. ;/

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top