How To Start, Stop, Restart and Manage Apache Web Server In Linux?

Apache or Apache 2 is the most popular web server on the internet. We have set up our Apache server and made some configuration change we want to activate the changes. To active the changes, the Apache server must be restart. In this post, we will look at how to restart Apache in different ways in Ubuntu and CentOS.

Start Apache with systemctl Command

Systemctl is a tool for managing Linux services, operating system state, run levels, etc. Systemctl became very popular and currently supported CentOS, Fedora, Ubuntu as default service manager.

Ubuntu, Debian, Mint, Kali:

$ sudo systemctl restart apache2
Start Apache with systemctl Command
Start Apache with systemctl Command

CentOS, Fedora:

$ sudo systemctl restart httpd

If we look status line starts with  Active we can see that Apache2 service is started 5 seconds ago. Another way perhaps a more complicated way to restart Apache2 with systemctl command is first stopping the service and then starting it.

Ubuntu, Debian:

$ sudo systemctl stop apache2
$ sudo systemctl start apache2
Start Apache with systemctl Command
Start Apache with systemctl Command

CentOS, Fedora:

$ sudo systemctl stop httpd
$ sudo systemctl start httpd

Start and Restart Apache with apachectl Command

An alternative way to restart Apache 2 service is using native tool apachectl . The syntax of apachectl is like below.

apachectl COMMAND

We can use restart command with apachectl.

$ sudo apachectl restart
Start and Restart Apache with apachectl Command
Start and Restart Apache with apachectl Command

As we see apachectl provides restart operation logs too.

Start and Restart Apache with Init.rc Script

Apache provides init.rc related daemon control script under /etc/init.d . These scripts can be used to restart Apache too.

Ubuntu, Debian:

$ sudo /etc/init.d/apache2 restart

CentOS,Fedora:

$ sudo /etc/init.d/httpd restart

We need root privileges too to use this init.rc script. After restart script provides information about restart operation. In this example, it seems everything done without a problem.

Leave a Comment