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
$ 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.
$ sudo systemctl stop apache2 $ sudo systemctl start apache2
$ 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.
We can use restart command with apachectl.
$ sudo apachectl restart
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.
$ sudo /etc/init.d/apache2 restart
$ 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.