Ubuntu CentOS Restart Apache Web Server
Apache or Apache 2 is most popular web server in the internet. We have setup our Apache server and made some configuration change we want to active the changes. To active the changes Apache server must be restart. In this post we will look how to restart Apache in different ways in Ubuntu and CentOS.
Systemctl is 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.
$ sudo systemctl restart apache2
$ sudo systemctl restart httpd
If we look status line starts with Active we can see that Apache2 service is start 5 second ago.
Another way perhaps more complicated way to restart Apache2 with systemctl 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
Alternative way to restart Apache 2 service is using native tool apachectl . 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.
Apache provides init.rc related daemon control script under /etc/init.d . This 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 problem.