Restart Apache Ubuntu

Introduction

Apache can be defined as a part of the famous LAMP (short for Linux, Apache, MySQL, PHP) software stack. By default, it is contained with the current release of the Ubuntu 18.04 version.

This article will show us how we can start, restart, and stop Apache service using the terminal on Ubuntu.

Primarily, Apache is used for serving both dynamic web pages and static content on the WWW (World Wide Web). Various applications of the web are created expecting the features and environment that Apache facilitates.

We can use one of the below techniques for restarting, starting, or stopping our httpd (Apache) server on Ubuntu:

  1. systemctl command: This command works only on systemd-based Ubuntu such as the 16.04 LTS version and above.
  2. /etc/init.d/apache2 command: It is a sys v init format script for starting, stopping, or restarting the service of Apache2 under Ubuntu or Debian Linux.
  3. service command: It works in almost all the distributions of Linux including Ubuntu and Debian.
  4. upstart command: This command works only on some specific releases of Ubuntu.
  5. apache2ctl command: This command should run on every Unix and Linux-like operating system.

Prerequisites

  • Have a user account along with root or sudo privileges
  • A configured and installed Apache installation
  • By default, included the apt package manager
  • A terminal/command line window

Installing Apache2 on Ubuntu

We can download or install Apache2 service on our Ubuntu computer by using the following command.

First, we need to update our system by using the below command:


Restart Apache Ubuntu

After updating the system, we need to run the following command:


Restart Apache Ubuntu

Commands to Start, Restart, or Stop Apache Web Server for New Ubuntu Releases

Start Apache Server

We can use a command for Ubuntu users using 18.04 and 16.04 versions and other Debian-based users. The command will be used in the command line window for starting Apache. The command is mentioned below:


Restart Apache Ubuntu

We can also see the status of whether Apache has been enabled using the command:


Restart Apache Ubuntu

The above command will show the active (running) message if it's running.

Stop Apache Server

We can use a command to stop the Apache server. The command is mentioned below:

We can also see the status of whether Apache has been disabled using the command:


Restart Apache Ubuntu

The above command will show the inactive (dead) message if it's stopped running or disabled.

Restart Apache Server

We can use a command in our terminal window for restarting the Apache server. The command is mentioned below:

The above command will display that it's up and again running if Apache was disabled previously.


Restart Apache Ubuntu

Commands to Start, Restart, or Stop Apache Web Server for Older Ubuntu Releases

Start Apache Server

We can use a command in our terminal window for starting Apache server for Debian and Ubuntu users using an older release. The command is mentioned below:

or,

We can also see the status of whether Apache has been enabled using the command:

or,


Restart Apache Ubuntu

The above command should show the active (running) message if it's running.

Stop Apache Server

We can use a command to stop the Apache server. The command is mentioned below:

or,

We can also see the status of whether Apache has been disabled using the command:


Restart Apache Ubuntu

The above command should show the inactive (dead) message if it's stopped running or disabled.

Restart Apache Server

We can use a command in our terminal window for restarting the Apache server. The command is mentioned below:

or,


Restart Apache Ubuntu

Important: The command, i.e., restart can take many moments to complete. It is depending on our server configuration's complexity. It can lead to disruptions for various users who depend on the server if we are running a complex or large server configuration.