How to restart apache HTTPD on Ubuntu 22.04

How to Restart Apache HTTPD on Ubuntu 22.04

We’re here to discuss how to restart Apache HTTPD on Ubuntu 22.04 and why it is among the most commonly used web servers. So keep reading to find out more.

Apache HTTPD is an open-source and one of the most widely used web servers developed and maintained by the Apache software foundation. And we’re going to talk about the ways to restart the apache server on Ubuntu. 

Chances are when you’re restarting your apache web server means you have changed some of the critical system configurations. On the other hand, it could also be that your apache server is malfunctioning.

How to Restart Apache HTTPD on Ubuntu 22.04

To run the steps mentioned in this article, you will need a Ubuntu system with the latest version of apache running. You also need access to a root user or non-root user with sudo privileges.

About Apache Web Server

Apache web server is an open-source hypertext transfer protocol (HTTP). The Apache web server is used by 67% of websites worldwide. It can be used as a standalone development environment with Linux, Apache, MySQL, and PHP (LAMP) stack. The following are the main features of the apache web server:

  • It supports HTTP 2.0
  • It provides high-speed performance
  • It supports static files
  • It includes support for file transfer protocol (FTP)
  • It offers a great deal of reliability and security
  • It can be extended with the help of various plug-ins and modules

Installation of the apache web server

The apache server can be used with any operating system of your choice. However, in this article, we will talk exclusively about Ubuntu. To install the apache web server in Ubuntu, the following command can be used:

$ sudo apt install apache2 -y

Once you’re done installing the Apache web server, you can check its version and confirm its status with the help of the following command:

$ apache2 -version

Now, we need to configure it so that firewalls can pass the web server’s traffic.

The ufw rules can be added via the following command:

$ sudo ufw allow 'Apache'

Ubuntu systemd service

Ubuntu is equipped with the systemd service by default. It is an init system and service manager with support for features such as snapshot, process tracking, and daemon management. When you install an apache web server, it registers itself as a dedicated service with systemd. 

The service is named apache2.service. The advantage of this approach is the ease of management with systemctl and service utilities. The service command is an essential utility primarily used for service management. For instance, the following is the basic structure for using the systemctl service:

$ sudo systemctl <action><service_name>

Where you will specify the specific action to be performed on a service. Similarly, the following command structure can be used for service utility:

$ sudo service <service_name><action>

To start the apache web server on system boot, the following command can be used:

$ sudo systemctl enable apache2.service

In contrast, to disable the boot on startup, you can use the following command:

$ sudo systemctl disable apache2.service

Restarting the apache httpd service

Now we will discuss the basic steps to restarting an apache web service.

Checking the status

The first step is to check the apache server’s status. For this purpose, the following command can be used:

$ sudo systemctl status apache2.service

Alternatively, you can also use the following command:

$ sudo service apache2 status

We will then browse the web server on a browser. First, find the internet protocol (IP) address of your machine using the following command:

$hostname -I

Then, open your favorite browser and type the IP address in the uniform resource locator (URL) address bar. You will see the welcome page of the server.

Reloading the web service

If the apache server runs, we can stop or restart the service using the systemctl or service commands. Alternatively, if you just need to reload the service instead of a complete restart, you can use the following commands:

$ sudo systemctl reload apache2.service

The same can be achieved with the service commands below:

$ sudo service apache2 reload

Tip: The reload command gracefully restarts the web server. Currently, open connections are not aborted. A command SIGUSR1 is sent to the daemon. For the restart, a signal SIGHUP is sent to the daemon.

Restarting apache httpd using systemctl

The recommended approach to restarting the apache web server is using systemctl. To stop apache web service using systemctl, open the Terminal and type the following command:

$ sudo systemctl restart apache2.service

Restarting apache httpd using the service

The service utility can also be used for essential service management. Using this tool, the services can be restarted by using the following command:

$ sudo service apache2 restart

Tip: Instead of restarting the service, you can just skip that part and do it manually. The service can be stopped by using the following command:

$ sudo systemctl stop apache2.service

Or the following command can also be used:

$ sudo service apache2 stop

Now, to start the service, use the following command:

$sudo service apache2 start

In this article, we have talked about the apache web server. We briefly introduced its distinctive features and discussed the various approaches to start, stop or reload it in multiple ways. These steps can be achieved with systemd or service utilities. 

If this guide helped you, please share it.

Leave a Reply
Related Posts