How to Install and Configure Apache Web Server on Ubuntu

Apache HTTP Server is one of the most popular and reliable web servers in the world. If you are setting up a new Ubuntu server for web hosting, installing Apache is usually the first step. This guide will show you how to install Apache and configure your firewall to allow web traffic via the Linux terminal.

Step 1: Install Apache

Before installing any new software, it is best practice to update your local package index to ensure you get the latest version available in the Ubuntu repositories.

sudo apt update

Once the update is complete, install the apache2 package:

sudo apt install apache2 -y

Step 2: Adjust the Firewall

If you are using UFW (Uncomplicated Firewall) on your Ubuntu server, you need to open port 80 (HTTP) and port 443 (HTTPS) so external users can access your websites. Apache registers application profiles with UFW upon installation.

To allow both HTTP and HTTPS traffic, run the following command:

sudo ufw allow 'Apache Full'

You can verify the status of your firewall changes using:

sudo ufw status

Step 3: Verify the Installation

Apache should start automatically after installation. You can check the status of the Apache service to ensure it is running without errors:

sudo systemctl status apache2

Finally, open a web browser on your computer and navigate to your server’s public IP address (e.g., http://your_server_ip). You should see the default “Apache2 Ubuntu Default Page”, confirming that your web server is successfully installed and accessible.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.