How to Restart Apache on Ubuntu and CentOS

How to restart apache on ubuntu and centos

As a Linux sysadmin running an Apache web server, it won't be long before you'll have the need to restart the service. Starting and restarting Apache is a common task that every admin should know. In this tutorial, we'll look at how to restart the Apache service in both Ubuntu (apache2) and CenOS (httpd) systems. We'll cover different versions of both operating systems, as the syntax has changed slightly on CentOS and the Apache versions.

Restart Apache Ubuntu

Ubuntu is a highly popular Linux-based operating system and a Debian-based distribution. Restarting the Apache service on Ubuntu servers is an easy and quick job. You'll need shell access to your server including a sudo user or directly as root.

Apache 2.2

Version 2.2 has now reached the end of life (EOL) and 11th July 2017, for those still running Apache 2.2, the easy way to restart Apache is by using the service CLI command. Be sure to upgrade to Apache 2.4 (or higher) as soon as possible.

sudo service apache2 restart

Apache 2.4

The current version of the Apache server software provides a similar way to restart Apache, but in this version, it is the systemctl command instead of the service CLI command.

sudo systemctl restart apache2

Restart Apache CentOS (and RHEL, CloudLinux)

CentOS is another popular Linux-based operating system and Red Hat-based distribution. Unlike Ubuntu, where the Apache service is called apache2 on CentOS it is called httpd.

CentOS 6

If you are running this version of CentOS, you should upgrade as soon as possible. Version 6 reached EOL on 30th November 2020. However, in order to restart Apache you can do so by running this command below.

sudo service httpd restart

CentOS 7

The current version of CentOS with support until 30th June 2024, using systemctl and restart along with the httpd service name will get the Apache server restarted in no time.

sudo systemctl restart httpd

CentOS 8

CentOS version 8 has the same command format as version 7, however, this version of CentOS reached EOL on 31st December 2021. Against semantic versioning 8 hit EOL before version 7!

sudo systemctl restart httpd

Bitnami restart apache

If you're set up using Bitnami the restart process will be different from what has been mentioned above. In order to restart Apache on Bitnami, you can use the ctlscript.sh and pass it restart and then the service, in this case, that's Apache.

sudo /opt/bitnami/ctlscript.sh restart apache

How to Restart Apache in cPanel

Some web hosting environments don't provide access to the service with an SSH shell, sometimes because the box is a shared setup. If that's the case and you require to restart Apache in cPanel, follow the steps below.

  1. Access the WHM control panel using the root credentials.
  2. From the sidebar menu locate the search feature.
  3. Enter "Restart" in the search field.
  4. Select the option labeled "HTTP Server (Apache)."
  5. Confirm the restart action by clicking on the "Yes" button.
  6. After a short wait, check your websites are back up and running

How to Restart Apache in Plesk

Plesk provides a very easy-to-use interface for managing services on your web server. In order to restart Apache in Plesk, follow the step-by-step guide below.

  1. Sign in to Plesk using the admin credentials.
  2. Navigate to Tools & Settings and select Services Management.
  3. Locate the "Web Server (Apache)" option.
  4. Click on the restart icon (the half-circular arrow) next to "Web Server (Apache)".
  5. After a short wait, check your websites are back up and running

Should your website fail to load as usual, it is best to view the Apache error logs and view the status of Apache via the CLI for reasons why it may have failed to restart successfully. Within Plesk and cPanel, you can do this by viewing their control panels, and Ubuntu and CentOS can be performed on the command line.

In Ubuntu, you'll typically find (in standard Apache set-ups the error logs in the following location; /var/log/apache2/error.log

In CentOS, you'll typically find (in standard Apache set-ups the error logs in the following location; /var/log/httpd/error_log

It is worth noting that if you are using a custom Apache configuration or Virtual Hosts, the error log may be in a different location. You should consult your configuration files for the exact location.

Conclusion

It can be hard to remember all the different commands for the different types of Linux-based operating systems. Having this quick guide can help you quickly restart Apache in times of need. If you're using Cloudflare to frontload your website, it is always a good idea to turn on developer mode to ensure you're not served a cached version whilst you debugging/restarting important services. Dev mode will be re-enabled after the default four hours as elapsed.

  • On CentOS, the service name is httpd
  • On Ubuntu the service name is apache2
  • If you are running Apache 2.2 or CentOS 6, consider upgrading as soon as possible!
  • You may need to wait on average 5 to 10 seconds before seeing the websites come back online

Senior PHP developer. Author of Dev Lateral guides and tools. The complete place for PHP programmers. Available to hire to help you build or maintain your PHP application.

Looking for industry-leading PHP web development?

API development WordPress Hosting ★ and more 🐘

We use cookies to enhance your browsing experience, and analyse website traffic in accordance with our Privacy and Cookie Policy. Our cookies, including those provided by third parties, collect anonymous information about website usage and may be used for targeted advertising purposes. By clicking "Reject non-essential" you can opt out of non-essential cookies. By clicking "Accept all" you agree to the use of all cookies.


Reject non-essential Accept all