How to restart Apache on Ubuntu 20.04 step-by-step instructions

There are two main ways on how to restart the Apache webserver on Ubuntu Linux:

  • reload – Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files via apache2ctl configtest before initiating the restart to catch the most obvious errors. However, it is still possible for the daemon to die because of problems with the configuration.
  • restart – Restarts the Apache daemon by sending it a SIGHUP. If the daemon is not running, it is started. This command automatically checks the configuration files via configtest before initiating the restart to catch the most obvious errors. However, it is still possible for the daemon to die because of problems with the configuration.

Even though both above methods check the configuration during the restart/reload procedure it is always advisable to check the Apache web-server configuration using the following command:

$ apachectl configtest
Syntax OK

Since the Ubuntu 20.04 Focal Fossa Server/Desktop is based on systemd the following two methods are recommended to restart the the Apache web server.

DID YOU KNOW?
You can check whether the Apache 2 web server has been fully restarted by checking for Main PID number using the sudo systemctl status apache2 command before and after the restart.

  1. Using the systemcltcommand gracefully reloads the Apache webserver:
    $ sudo systemctl reload apache2
    
  2. This method fully restarts the Apache 2 web server:
    $ sudo systemctl restart apache2
Was this answer helpful? 0 Users Found This Useful (0 Votes)