How to Start, Stop, or Restart Apache Server on Ubuntu

Introduction

Apache is part of the popular LAMP (Linux, Apache, MySQL, PHP) stack of software. It is included with the latest version of Ubuntu 18.04 by default.

This guide will show you how to start, stop, and restart Apache service on Ubuntu using the terminal.

Prerequisites

  • Access to a user account with sudo or root privileges
  • An installed and configured Apache installation
  • The apt package manager, included by default
  • A command-line/terminal window (Ctrl-Alt-T)

Ubuntu 18.04, 16.04, and Debian 9.x Commands

Start Apache Web Server

For Ubuntu users with versions 16.04 and 18.04 and Debian 9.x users, use the following commands in the terminal window to start Apache:

sudo systemctl start apache2

Check status to see whether Apache is enabled with the command:

sudo systemctl status apache2

If it is running, it should display the message active (running) as in the image below.

Checking status to see if Apache is enabled

Stop Apache Web Server

Use the following commands in the terminal window to stop Apache:

sudo systemctl stop apache2

Check status to see whether Apache is disabled with the command:

sudo systemctl status apache2

If it has stopped running, it should display the message inactive (dead) as in the image below.

inactive message on apache web server after being stopped

Note: Learn how to check Apache version via CLI, WHM or cPanel.

Restart Apache Web Server

To restart Apache use the command:

sudo systemctl restart apache2

If Apache was previously disabled, a status check will show that it is up and running again.

screenshot after restarting apache ubuntu

Ubuntu 14.10 or older Debian

Start Apache

For Ubuntu and Debian users with an older version, use the following commands in the terminal window to start Apache:

sudo service apache2 start

or

sudo /etc/init.d/apache2 start

Check status to see whether Apache is enabled with the command:

sudo service apache2 status

or

sudo /etc/init.d/apache2 status

It should display the message active (running).

Stop Apache

To stop Apache use the following command:

sudo service apache2 stop

or

sudo /etc/init.d/apache2 stop

Check status to see whether Apache is disabled with the command:

sudo /etc/init.d/apache2 status

It should display the message inactive (dead) as in the image below.

Restart Apache

To restart Apache use the command:

sudo service apache2 restart

or

sudo /etc/init.d/apache2 restart

Note: The restart command can take several moments to complete, depending on the complexity of your server configuration. If you’re running a large or complex server configuration, this can cause disruptions for users who rely on the server.

Conclusion

Starting, stopping and restarting the Apache service on Ubuntu is straightforward. Knowing how to do these basic tasks from the terminal line makes the task faster and easier.

Was this article helpful?
YesNo
Goran Jevtic
Goran combines his leadership skills and passion for research, writing, and technology as a Technical Writing Team Lead at phoenixNAP. Working with multiple departments and on various projects, he has developed an extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
How To Install Apache On Ubuntu 18.04
March 22, 2019

This guide will help you install the Apache web server on an Ubuntu Linux 18.04 operating system.
Read more
How To Start, Stop, Or Restart Apache Server On CentOS 7
January 23, 2019

In this SIMPLE Updated Tutorial Learn How to restart, start, & stop Apache web server on the CentOS 7 Linux operating system. Find out how now!
Read more
How To Set Up & Configure ModSecurity On Apache
March 11, 2019

ModSecurity is an Open-source firewall application for Apache. Learn how to Setup & Configure ModSecurity on Apache (Debian, Ubuntu, CentOS).
Read more
How To Install MySQL 8.0 In Ubuntu 18.04
December 12, 2018

MySQL is an open-source relational database server tool for Linux operating systems. It is widely used...
Read more