How To Restart (Stop-Start) Apache Web Server?

Apache or Apache2 is a popular web server software used by millions of websites. Apache webserver can run PHP web applications and generally used as Linux+Apache+MySQL+PHP formula in order to create a full-stack web application. Apache Web Server is a service that may be required to restart in different cases.

Apache or Apache2 or Httpd

Before starting to explain apache webserver restart we should talk about the Apache web server names. Apache web server is a long-time project which is created in the 1990s and named Apache but Apache version 2 is named Apache2. Also the RPM-based distributions like CentOS, Fedora, RHEL name it as Httpd. So while restarting it generally the httpd term is used to describe Apache.

Check Apache Web Server Status

First, we will check the status of the Apache webserver whether it is running or stopped. We will use the systemctl status command and provide the service name where apache2 is used for Ubuntu, Debian, Mint and Kali , httpd is used for Fedora, CentOS, RHEL.

Ubuntu, Debian, Mint, Kali:

$ systemctl status apache2
Ubuntu, Debian, Mint, Kali Apache Web Server Status

Fedora, CentOS, RHEL:

$ systemctl status httpd
Fedora, CentOS, RHEL Apache Web Server Status

Alternatively the Apache service status can be displayed with the following commands using init scripts.

Ubuntu, Debian, Mint, Kali:

$ sudo /etc/init.d/apache2 status

Fedora, CentOS, RHEL:

$ sudo /etc/init.d/httpd status

Restart Apache Web Server with systemctl Command

The systemctl command is a defacto command used to manage Linux services. It is provided by all major Linux distributions like Ubuntu, Debian, Mint, Kali, CentOS, Fedora, RHEL, etc. The systemctl restart command can be used to restart the Apache webserver. The service management requires root privileges and the sudo command can be used for normal users to restart apache. Also, you can run as root without providing the sudo command.

READ  Copy Directory with SCP Command

Ubuntu, Debian, Mint, Kali:

$ sudo systemctl restart apache2

Fedora, CentOS, RHEL:

$ sudo systemctl restart httpd

Restart Apache Web Server with init.d

Linux provides the init.d scripts which are used to manage services with scripts. The init.d scripts were standard 5 years ago but replaced with the systemctl command. The init.d scripts are located under /etc/init.d with the related service name where apache is /etc/init.d/apache2. Like the systemctl command, it requires root privileges which can be provided with the sudo command.

Ubuntu, Debian, Mint, Kali:

$ sudo /etc/init.d/apache2 restart

Fedora, CentOS, RHEL:

$ sudo /etc/init.d/httpd restart

Restart Apache Web Server with service Command

The service command also provided by major Linux distributions in order to manage services. Even it has replaced with the systemctl command it is provided currently. The service command also requires the sudo command for root privileges.

Ubuntu, Debian, Mint, Kali:

$ sudo service apache2 restart

Fedora, CentOS, RHEL:

$ sudo service httpd restart

Restart Apache Web Server with apachectl Command

The Apache project and package also provides the apachectl command which is used to control apache web server services. It can be used to restart the apache easily by providing the root privileges with sudo. As a command apachectl can be used for all Linux distributions like Ubuntu, Debian, Mint, Kali, CentOS, RHEL like below.

Ubuntu, Debian, Mint, Kali, Fedora, CentOS, RHEL:

$ sudo apachectl restart

Leave a Comment