Apache is an open-source and cross-platform HTTP server. It comes loaded with powerful features and can be further extended with a wide variety of modules.

 

If you are a developer or system administrator, the chances are that you’re dealing with Apache on a regular basis.

 

Starting, stopping, and restarting/reloading is the most common tasks when working with an Apache webserver. The commands for managing the Apache service are different across Linux distributions.

 

Most of the recent Linux distributions are using SystemD as the default init system and service manager. Older distributions are based on SysVinit and using init scripts to manage services. Another difference is the name of the service. In Ubuntu and Debian, the Apache service is named apache2, while in Red Hat based system such as CentOS, the name of the service is httpd.

 

The instructions assume that you are logged in as root or user with sudo privileges.

 

Both SystemD service units and SysVinit script takes the following arguments to manage the Apache service:

  • start: Starts the Apache service.
  • stop: Terminates the Apache service.
  • restart: Stops and then starts the Apache service.
  • reload: Gracefully restarts the Apache service. On reload, the main Apache process shuts down the child processes, loads the new configuration, and starts new child processes.
  • status: Shows the service status.

 

Start, Stop and Restart Apache on Ubuntu and Debian

 

SystemD is a system and service manager for the latest Ubuntu (18.04, 16.04) and Debian (10, 9) releases.

 

Execute the following command to start the Apache service:

sudo systemctl start apache2

 

Execute the following command to stop the Apache service:

sudo systemctl stop apache2

 

Whenever you make changes to the Apache configuration, you need to restart the server processes. Execute the following command to restart the Apache service:

sudo systemctl restart apache2

 

Older (EOLed) versions of Ubuntu or Debian are using init.d scripts to start, stop and restart the Apache daemon:

sudo service apache2 start
sudo service apache2 stop
sudo service apache2 restart

 

Start, Stop and Restart Apache on RHEL/CentOS

Systemd is the system and service manager for RHEL/CentOS 7 and 8.

 

Start the Apache service:

sudo systemctl start httpd

 

Stop the Apache service:

sudo systemctl stop httpd

 

Restart the Apache service:

sudo systemctl restart httpd

 

If you have CentOS 6 (or earlier) use the following commands to start, stop and restart the Apache daemon:

sudo service httpd start
sudo service httpd stop
sudo service httpd restart
Was this answer helpful? 0 Users Found This Useful (0 Votes)