Mac OS Mountain Lion - Apache works, but localhost does not work

I downloaded the Apache web server on Mac OS Mountain Lion using the command

sudo apachectl start 

However, when I try to open localhost in Firefox, I get a message

Not Found: The requested URL / was not found on this server. Apache / 2.2.21 (Unix) Server DAV / 2 on the local host Port 80

I edited both httpd.conf and httpd.conf.default to change

 #ServerName www.website.com 

to

 ServerName localhost 

It still does not work. Any suggestions?

+8
unix apache osx-mountain-lion localhost macos
source share
3 answers

You should check the permissions in the folder specified as "DocumentRoot" in your "httpd.conf" and allow at least read access for the Apache user (which should be "_www" by default).
Otherwise, you can do "sudo chmod 755" in the "DocumentRoot" folder.
By the way, you only need to change the file "httpd.conf", since "httpd.conf.default" is the default configuration, which you can use if you want to restore the original Apache configuration by simply overwriting "httpd. Conf" with the file "httpd .conf.default ".
I assume that you did not enable name-based virtual hosts, because when you enable name-based virtual hosts, the document root in the main configuration is ignored; instead, the root will be used for the matching host name, and if it does not match, it will be the first virtual host by default.
Finally, when you have problems, the first thing to check is always the Apache error log file.
The location of the error log can be found by looking at the "ErrorLog" directive in the Apache configuration file.

+5
source share

To verify that the process is listening on port 80, you can use lsof in the terminal window:

 $ sudo lsof -iTCP:80 -sTCP:LISTEN COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 88 root 4u IPv6 0xffffff8018804600 0t0 TCP *:http (LISTEN) httpd 90 _www 4u IPv6 0xffffff8018804600 0t0 TCP *:http (LISTEN) httpd 14843 _www 4u IPv6 0xffffff8018804600 0t0 TCP *:http (LISTEN) 

This will confirm that you have successfully enabled apache.

(I have xcode installed, but I think lsof is part of a normal installation)

ADDED:

This confirms that apache is listening on port 80. The next step I would like to do is look at the access logs to see what apache started when you requested "/", as shown in the apache error returned to your browser. This is what mine shows. Note that the HTTP GET request is displayed with a return code of 200 (success):

 bash-3.2# grep 'GET / ' /private/var/log/apache2/access_log 127.0.0.1 - - [12/Sep/2012:16:46:45 -0400] "GET / HTTP/1.1" 200 44 127.0.0.1 - - [12/Sep/2012:16:49:44 -0400] "GET / HTTP/1.1" 200 44 

You can also confirm that the URL of your browser is requesting by updating the browser window and then confirming that apache is logging this new request in access_log.

+6
source share

Comment on all IfDefine !WEBSERVICE_ON , keeping the contents inside - there is no WEBSERVICE on Mountain Lion.

+1
source share

All Articles