Apache HTTP Server (httpd) was included out of the box of Mac OS X Mountain Lion (10.8) if you don’t know already. Prior to Mac OS X 10.8 (Mountain Lion) can simply turn on “Web Sharing” to start Apache Web Server service, but from 10.8 onward you’ll need to use command line to start the Apache web server.
osxdaily.com mentioned here that we can use
apachectl command to start and stop apache web server service from command line like the following:
sudo apachectl start
sudo apachectl stop
Another way to start and stop apache web server is using the
httpd command like the following:
sudo httpd -k start
sudo httpd -k stop
If you start the apache web server using apachectl command, you only able to stop it using the apachectl command and not the
httpd -k command. This is also works vice versa.
Here’s an example on how to do it in terminal:
From both pictures above, I uses
netstat -an | grep LISTEN command to show all open services on my Mac computer. A line indicating a service is LISTENING on port 80 (
tcp46 ... *.80 ... LISTEN) means a web server is currently running on my Mac computer. And when those line are not in, then the web server is off.
The default apache web server configuration are in