How Do You Restart Apache on Linux?

The Apache HTTP Server, commonly known as Apache, is a widely used open-source web server software in Linux. It plays a crucial role in hosting and serving web content. Apache is known for its stability, performance, and security features, making it a popular choice for web servers. It provides a flexible and scalable platform for hosting websites, applications, and services.

Apache’s importance in Linux lies in its central role in the web ecosystem. It is the foundation for hosting websites, handling HTTP requests, and delivering web pages. With its modular architecture and extensive community support, Apache offers flexibility, customization, and robust security features.

Being a Linux and Apache user, you must be familiar with the importance of restarting Apache, as it has to be the core operation after performing any modification on the server. This post will enlist the possible commands to restart Apache on Linux.

Note: As a reference, the commands will be executed on Ubuntu 22.04 which has the systemd as its init system.

How to Restart Apache on Linux?

The primary operation to restart any server on Linux depends on the initialization system used by that. So, restarting Apache also depends on the init system used by your Linux system. It varies from modern to older Linux systems. Three possible init systems are used in Linux, i.e., /etc/init.d, SysV, and systemd. This section will enlist all the commands used to restart Apache on Linx with respect to the init system being used.

Prerequisite: Check the init System of Your Linux System

Before getting into the details of the methods, it is recommended to check the init system in use and then choose the appropriate method as per that.

Step 1: Check the Status of the init System

First, use the ps 1 command to check the status of the active init system. The ps 1 command will show the status of the first process, which is the init system (as it is initiated at the very start)

$ ps 1

How Do You Restart Apache on Linux? |

If you look at the output, the “/sbin/init” is the symbolic link to the init process.

Step 2: Evaluate the Symbolic Link

Now, it is recommended to evaluate that symbolic link using the stat command as follows:

$ stat /sbin/init

How Do You Restart Apache on Linux? |

It can be seen that the “sbin/init” is directed towards the systemd, which shows that the systemd is the init system being used by the system.

Restart Apache on Systemd-Based Systems | Using systemctl Command

The systemd is a modern init system and service manager that has become the default in many newer Linux distributions. It aims to improve the boot process, parallelize service startup, and simplify service management. The systemd operates based on targets, which are more flexible and dynamic than runlevels. It provides compatibility with SysV init scripts but also introduces its own unit files (ending with .service, .socket, .timer, etc.) that define how services should be managed.

The commands to restart Apache on systemd-based Linux systems are given as follows:

$ sudo systemctl restart apache2
$ sudo systemctl restart httpd

How Do You Restart Apache on Linux? |

Restart Apache on SysV-Based Systems | Using service Command

SysV init (System V init) is a traditional initialization system used in many older Linux distributions. It follows a sequential and script-based approach to manage system services during startup. SysV init relies on runlevels, which are predetermined system states with specific sets of services running. The init scripts in /etc/init.d are executed by the init daemon (initd) to start or stop services based on the current runlevel or user commands.

A system that depends on SysV init-based systems, the following commands can be used to restart Apache on SysV init-based systems:

$ sudo service apache2 restart
$ sudo service httpd restart

Restart Apache on init-based Systems | Using /etc/init.d Script (Older Systems)

The /etc/init.d is a directory in Linux that contains the scripts used for managing system services in traditional SysV init systems. These scripts are often referred to as init scripts or init.d scripts, control the startup, shutdown, and management of individual services. Each script within the /etc/init.d directory corresponds to a specific service and provides commands such as start, stop, restart, and status to control the service’s behavior.

To restart Apache on a system that depends on the /etc/init.d script, use one of the following commands:

$ sudo /etc/init.d/apache2 restart
$ sudo /etc/init.d/httpd restart

Wrap Up

Apache is a vital web server software in Linux, known for its stability and performance. It is a flexible platform for hosting web content and plays a central role in the web ecosystem. Restarting Apache is a critical operation after making modifications, and the method varies depending on the init system used in Linux. Systemd, SysV, and /etc/init.d are the three common init systems.

The systemd-based systems use “systemctl restart” commands, SysV-based systems utilize “service restart” commands and older systems rely on the “/etc/init.d” script for restarting Apache. This post has enlisted the possible methods for all Linux systems (older as well as modern) to restart Apache.

Keep visiting Linux Genie for more Linux-based guides.

Print Friendly, PDF & Email