Install the Apache Web Server on Ubuntu 18.04, 12.04

Published on Apr 15, 2022

Apache is a popular open-source, cross-platform web server that is, by the numbers, the most popular web server in existence. In this quickstart article, we'll see how to install Apache server on Ubuntu, Debain.

Table of Contents

Install Apache

Update your packages:

sudo apt update -y

Now install Apache:

sudo apt install apache2 -y

Then enable and start webserver:

# enable
sudo systemctl enable apache2

# start
sudo systemctl start apache2

Adjust Firewall

First, check firewall is enabled or not:

sudo ufw status

# Status: active/inactive

If status is "active", then allow apache to server traffic:

sudo ufw allow 'Apache'

Check Webserver

Run this command to check website is running or not:

sudo systemctl status apache2

If it is running, you'll see an output like:

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Tue 2022-04-15 12:12:31 UTC; 7min ago
 Main PID: 2583 (apache2)
    Tasks: 55 (limit: 1153)
   CGroup: /system.slice/apache2.service
           ├─2583 /usr/sbin/apache2 -k start
           ├─2585 /usr/sbin/apache2 -k start
           └─2586 /usr/sbin/apache2 -k start

Now you can access default Apache webpage by visiting your server IP:


Add Virtual Host

In one server, we can host unlimited websites. It is called virtaul host/s. Let's add a domain:

Create the directory for your domain

sudo mkdir /var/www/

Assign ownership:

sudo chown -R $USER:$USER /var/www/

Set permissions:

sudo chmod -R 755 /var/www/

Create a sample index.html page:

nano /var/www/

Demo content:

    <title>Welcome to!</title>
    <h1>Success! Welcome to!</h1>

Now, create a new virtual host config file at location /etc/apache2/sites-available for domain

sudo nano /etc/apache2/sites-available/

And insert the follwing config block:

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot /var/www/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and close the config file. Then enable your virtual host file:

sudo a2ensite

Test for configuration errors:

sudo apache2ctl configtest

# output
# Syntax OK

Disable the default site (optional):

sudo a2dissite 000-default.conf

Finally restart Apache:

sudo systemctl restart apache2

Now visit your domain

That's all. Thanks for reading. 👍

Comments (0)