How to Start, Stop, and Restart Apache on Linux
Managing the Apache HTTP server is a fundamental skill for Linux
system administrators and web developers. Whether you are applying
configuration changes, troubleshooting errors, or performing routine
system maintenance, you will frequently need to control the status of
the web server. This guide provides the exact commands needed to start,
stop, and restart the Apache service across major Linux distributions,
including Ubuntu, Debian, CentOS, RHEL, and Fedora, using modern
systemd commands as well as legacy init.d
alternatives.
Managing Apache on Systemd Distributions
Modern Linux distributions—including Ubuntu 16.04 and later, Debian 8
and later, CentOS 7 and later, and all recent versions of RHEL and
Fedora—use systemctl to manage system services.
Note: The name of the Apache service depends on your operating system. Ubuntu and Debian-based systems refer to it as
apache2, while CentOS, RHEL, and Fedora refer to it ashttpd.
For Ubuntu and Debian Systems
To start the Apache service if it is currently offline:
sudo systemctl start apache2To stop the Apache service immediately:
sudo systemctl stop apache2To completely restart the Apache service (this will kill all active connections and spin up the server again):
sudo systemctl restart apache2If you have made configuration changes and want to apply them without dropping active user connections, use the reload command instead:
sudo systemctl reload apache2To check the current running status of your Apache server:
sudo systemctl status apache2For CentOS, RHEL, and Fedora Systems
To start the Apache service:
sudo systemctl start httpdTo stop the Apache service:
sudo systemctl stop httpdTo restart the Apache service entirely:
sudo systemctl restart httpdTo gracefully reload the configuration without severing active connections:
sudo systemctl reload httpdTo verify whether the Apache service is actively running:
sudo systemctl status httpdManaging Apache on Older Linux Distributions
If you are working on an older legacy server that does not utilize
systemd (such as Ubuntu 14.04 or CentOS 6 and older), you
must use either the service wrapper command or call the
init.d script directly.
Using the Service Command
The service command operates across most older platforms
and automatically routes your instruction to the correct directory.
Ubuntu/Debian legacy:
sudo service apache2 startsudo service apache2 stopsudo service apache2 restartCentOS/RHEL legacy:
sudo service httpd startsudo service httpd stopsudo service httpd restart
Using Init.d Scripts Direct Path
Alternatively, you can interact directly with the initialization
scripts located inside the /etc/init.d/ directory.
- Ubuntu/Debian legacy:
sudo /etc/init.d/apache2 restart - CentOS/RHEL legacy:
sudo /etc/init.d/httpd restart
Enabling Apache to Launch at Boot
Controlling the running state of the service does not dictate what happens when the physical or virtual machine reboots. If you want to ensure that Apache automatically starts up whenever your Linux machine turns on, you must enable the service.
To enable Apache to start automatically at system bootup:
- Ubuntu/Debian:
sudo systemctl enable apache2 - CentOS/RHEL:
sudo systemctl enable httpd
If you want to reverse this decision and prevent Apache from starting automatically when the computer boots up:
- Ubuntu/Debian:
sudo systemctl disable apache2 - CentOS/RHEL:
sudo systemctl disable httpd