Apache is one of the most widely deployed web servers. It’s free and open-source software developed and maintained by Apache Software Foundation. It offers fast performance, reliability, security, and customization with the help of numerous extensions and modules. It is estimated Apache powers about 67% of all the websites in the world.
This guide will showcase restarting the Apache HTTPD service on Ubuntu 22.04.
Prerequisites
To perform the steps demonstrated in this guide, you will need the following components:
-
- A properly-configured Ubuntu 22.04 system
- The latest version of the Apache web server was installed and configured. Check out installing Apache on Ubuntu 22.04
- Access to a non-root user with sudo permission
The Apache HTTPD Service
Ubuntu utilizes systemd, a popular init system and service manager for Linux. It has various features, such as snapshot support, process tracking, and daemon management. Besides Ubuntu, most modern Linux distros come with systemd pre-installed.
Upon installation, Apache registers a dedicated service, apache2.service, with a systemd for easier management. This allows us to manage the Apache service with tools like systemctl and service.
There are multiple scenarios where you may consider restarting Apache:
-
- Upon changing any mission-critical Apache configuration
- The server is acting weird
Restarting Apache HTTPD Using systemctl
Using systemctl is the recommended method of managing any service that uses systemd. The command structure is as follows:
Following the structure, restart Apache using the following command:
Restarting Apache HTTPD Using Service
The service command is another tool that can manage the system services. However, the service command structure is slightly different than the systemctl. Moreover, its functionality is also limited to basic service management.
The command structure is as follows:
Following this structure, use the following command to restart Apache:
Additional Tips
Checking Apache Status
The status of the service helps debug any abnormal behavior. To check the Apache service status, use any of the following commands:
Stopping Apache
If you want to manually shut down the Apache server, then run any of the following commands:
Reloading Apache
If you only modified the Apache configuration file(s), we can simply reload the service instead of a full-blown restart, saving time and energy. The command to reload Apache is as follows:
Enabling/Disabling Apache
If a service is enabled, then the systemd will start the service automatically upon booting. If not, then you have to activate the service manually. Similarly, if you disable a service, the systemd will no longer start it upon boot.
To start Apache on boot, use the following command:
To disable the Apache service, use this command:
Conclusion
In this guide, we successfully demonstrated restarting the Apache HTTPD on Ubuntu with the help of systemctl and service tools. We also showcased reloading, enabling, and disabling the Apache service.
The systemctl tool can accomplish a lot more. For example, check out listing all the services registered with systemd.
Often, Apache is installed as a part of the LAMP stack to provide a full-fledged web development environment. Learn more about setting up the LAMP stack on Ubuntu. Apache can also work with virtual hosts, serving multiple computing.