Get 33% off VPS Hosting using code 33OFF at checkout. View plans:
Apache is a free web-server solution. It provides an easy, user-friendly configuration process. However, installing it wrongly could lead to a wide variety of problems in the future.

This article will guide you through the process of installing the Apache2 web server in your Ubuntu or CentOS VPS correctly.


This article is officially made for Ubuntu 18.04 and higher. Installation on lower versions may vary depending on the software and package managers you already have installed. Consider using apt-get instead of apt if this is your case.

Update and upgrade current packages to avoid holding outdated and/or orphan packages in our system, as well as installing all the dependencies we need, we'll start this up by updating our repositories and upgrading our packages:

sudo apt update
sudo apt upgrade

Great! We can now follow that up by installing the apache2 package in our system. We can do this by executing:

sudo apt install apache2

Setting up the firewall
Ubuntu's firewall is well integrated with Apache2, we can set it up easily by just executing a few commands, without the hassle of editing files manually with Nano or Vim.

We'll first check all the 'profiles' that are available for us to install, we'll perform this by running:

sudo ufw app list

As can you see, we're now able to install three different Apache2 'profiles':

Apache: This profile will only enable port 80, which is used for normal, non-secured traffic.
Apache Full: This one will enable both ports 80 and 443, resulting in allowing all kinds of traffic: secure and non-secure.
Apache Secure: This will only enable por 443, meaning your web server will only allow secure traffic.
Depending on your requirements, you can enable any profile you want. For the sake of this guide, we'll enable the Apache Full profile. We'll do so by executing:

sudo ufw allow 'Apache Full'

After that, let's enable the firewall by executing:

sudo ufw enable

We can then verify our allowed traffic by executing:

sudo ufw status

Verifying the web server is up and running
We're almost done! Now, let's check if our web server is enabled in our system, and also if it's working externally.

We can check the Apache2 service status by running:

sudo systemctl status apache2

And we can finish things up by opening the server's ip in our preferred web browser.


Installing the Apache2 software in CentOS is easier, since configuration is done automatically by a few commands.

Updating packages
Just like we did with Ubuntu, let's update all our packages to ensure there are no unresolved dependencies or outdated libraries:

sudo yum update

Installing Apache2
Awesome! We can now safely install Apache2 in our CentOS server. Now, in CentOS's repositories, the Apache2 package is called httpd, we can install it by running:

sudo yum install httpd

Verifying installation
We're almost there! Let's start the Apache2 service and check its status by executing:

sudo systemctl start httpd
sudo systemctl status httpd

After that, we can open our server's IP in our browser. If it loads up the example page, we're good to go.
Was this article helpful?
Thank you!