To gracefully reboot the Apache server from the shell in Linux or Unix-based systems, you can use the apachectl command with the -k graceful option. Here are the steps:
- Open a terminal window on your Linux or Unix-based system.
- Switch to the root user or use the
sudocommand to run the following command:apachectl -k graceful
This will send a “graceful” restart signal to the Apache server, which will allow it to complete any existing requests and connections before shutting down and restarting.
If the
apachectlcommand is not found, you may need to install it first. In most cases, it can be installed with the Apache web server package. - Verify that the Apache server has restarted successfully by checking the Apache error log file. The default location of the error log file is
/var/log/httpd/error_logon Red Hat-based systems, and/var/log/apache2/error.logon Debian-based systems.You can use the following command to view the last 10 lines of the error log file:
tail -n 10 /var/log/httpd/error_log
If the Apache server has restarted successfully, you should see a message indicating that it has started, along with the date and time.
That’s it! You should now have successfully restarted the Apache server using the apachectl command with the -k graceful option.