Mac OS X Start / Stop / Restart Apache Web Server

Posted on in Categories , , , last updated May 6, 2017

How do I start or stop Apache/Apache 2 web server using a shell prompt option under Apple OS X (macos) UNIX operating systems?

The apachectl command act as Apache HTTP Server control interface. When you edit the Apache config file /etc/apache2/httpd.conf, you need to reload or restart the web server. Open the terminal application and type the following commands:

To stop Apache web server, enter:

sudo apachectl stop
OR
sudo apachectl -k stop

To start Apache web server again, enter:

sudo apachectl start
OR
sudo apachectl -k start

To restart apache web server, enter:

sudo apachectl restart
OR
sudo apachectl -k restart

To run a configuration file syntax test

sudo apachectl configtest

To reload apache web server after editing the config file

First edit the config file, run:
$ sudo vi /etc/apache2/httpd.conf
Make changes as per your needs. Close and save the file. To reload new changes, run:
sudo apachectl graceful
OR
sudo apachectl -k graceful

Sample session from above commands

Fig.01: apachectl in action on macOS
Fig.01: apachectl in action on macOS

You can displays a brief status report by visiting the url http://localhost:80/server-status in the web browser of your choice.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

6 comment

  1. For some interesting reason, apache keeps spawning off new process however I kill it. I tried apachectl and kill -SIGTERM but apache would be killed and another process will be spawned right away.
    Can you tell me why?

  2. I have the same problem as you Antony.
    I’ve used MAMP and then switched to Mac’s default Apache and problem still exists.
    I think it is somehow related to xdebug. I’ll try zend_debugger. If that doesn’t work, I’m switching to another operating system.

  3. Thank you! I was tinkering around with the built-in Apache web server because I’ll be messing around with learning some HTML and CSS on my own. I found a page explaining how to start and use it, but it didn’t say how to end the process. I didn’t notice any performance change but I also didn’t want wayward processes running on my machine. Many thanks!

Leave a Comment