Introduction
Before we begin talking about how to Start, Stop, or Restart Apache, let's briefly understand – What is Apache?
Apache is a cross-platform HTTP server that is publicly accessible. It is preloaded with advanced features and may be expanded with a wide range of modules.
If you work as a developer or a system administrator, you probably deal with Apache on a regular basis.
The most frequent operations while working with an Apache webserver are starting, stopping, and restarting/reloading. The commands for managing the Apache service vary depending on the Linux distribution.
SystemD is the default init system and service manager in most of the latest Linux distributions. Older distributions are SysVinit based and use init scripts to manage services. Another distinction is the name of the service. The Apache service is known as httpd
in Red Hat-based systems like CentOS, whereas apache2
is the name of the service in Ubuntu and Debian.
In this tutorial, you will see how to Start, Stop or Restart Apache.
Prerequisites
This tutorial assumes that you are logged in as root or user with sudo privileges.
To manage the Apache service, both SystemD service units and the SysVinit script takes the following arguments:
start
: Launches the Apache service.stops
: Terminates the Apache service.restart
: Stops the Apache service and then restarts it.reload
: Restarts the Apache service gracefully. The main Apache process shuts down the child processes, loads the new configuration, and starts new child processes upon reload.status
: Displays the service status.
To Start, Stop, and Restart Apache on Ubuntu and Debian
The latest versions of Ubuntu (20.04, 18.04) and Debian (10, 9) use SystemD as their system and service manager.
Start the Apache service using:
sudo systemctl start apache2
Stop the Apache service using:
sudo systemctl stop apache2
You must restart the server processes each time you change the Apache configuration. Restart the Apache service using:
sudo systemctl restart apache2
Older (EOLed) versions of Ubuntu or Debian start, stop, and restart the Apache daemon using init.d scripts:
sudo service apache2 start
sudo service apache2 stop
sudo service apache2 restart
To Start, Stop, and Restart Apache on RHEL/CentOS
RHEL/CentOS 7 and 8 use Systemd as the system and service manager.
Start the Apache service using:
sudo systemctl start httpd
Stop the Apache service using:
sudo systemctl stop httpd
Restart the Apache service using:
sudo systemctl restart httpd
Use the following commands to start, stop, and restart the Apache daemon if your CentOS 6 or earlier system uses SysV:
sudo service httpd start
sudo service httpd stop
sudo service httpd restart
Conclusion
We hope this detailed guide helped you understand how to start, stop, and restart the Apache webserver on various Linux systems.
If you have any queries, feel free to drop a comment below, and we'll be happy to help.