Mac OS X Start / Stop / Restart Apache Web Server

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

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: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.