Trying to run apache server on Mavericks

apacheweb-sharing

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!

Best Answer

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/.