=[object Object]

Mastering Apache Web Server Installation on Ubuntu: A Comprehensive Guide

Web Hosting

The Apache HTTP Server has stood the test of time as one of the most reliable web servers available. Since its inception in 1995, Apache has been favored for its open-source nature and extensive customization options. In a world increasingly reliant on web applications, setting up an Apache server on Ubuntu remains a relevant skill, especially with the latest Ubuntu 24.04 LTS release.

This guide will walk you through the steps to install Apache on Ubuntu, configure firewall settings, set up virtual hosts, and secure your server with HTTPS using Let’s Encrypt. Whether you’re hosting a personal blog or managing a cloud-based application, this tutorial aims to equip you with the tools and knowledge necessary for a successful deployment.

Prerequisites for Setting Up Apache

Before diving into the installation process, ensure that you have the following:

  • A non-root user with sudo privileges.
  • An active firewall to block unnecessary ports.
  • Access to the terminal on your Ubuntu server.

If you haven't set up a non-root user yet, refer to our initial server setup guide for Ubuntu.

Installing Apache on Ubuntu

Apache is available in Ubuntu's default package repository, making installation straightforward. Follow these steps to install Apache:

  1. Update your package index:

sudo apt update

  1. Install the Apache package:

sudo apt install apache2

After installation, verify that Apache is running:

sudo systemctl status apache2

If everything is functioning correctly, you should see a status of active (running).

Configuring the Firewall

Next, you will need to configure your firewall to allow web traffic. If you are using UFW (Uncomplicated Firewall), follow these steps:

  1. Check available application profiles:

sudo ufw app list

  1. Allow both HTTP and HTTPS traffic by enabling the Apache Full profile:

sudo ufw allow 'Apache Full'

To verify that the rule is applied, run:

sudo ufw status

This will confirm that Apache is now allowed through the firewall.

Setting Up Virtual Hosts for Multiple Domains

If you plan to host multiple websites on your server, virtual hosts are essential. This allows each domain to have its own configuration. Here’s how to set it up:

  1. Create a directory for your domain:

sudo mkdir /var/www/example.com

  1. Assign ownership to your current user:

sudo chown -R $USER:$USER /var/www/example.com

  1. Create a simple index.html file:

sudo nano /var/www/example.com/index.html

Insert the following HTML content:

<html><head><title>Welcome to example.com!</title></head><body><h1>Success! The example.com virtual host is working!</h1></body></html>

  1. Create and configure your virtual host file:

sudo nano /etc/apache2/sites-available/example.com.conf

Populate it with:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

Enable the site:

sudo a2ensite example.com.conf

And disable the default site:

sudo a2dissite 000-default.conf

Finally, test your configuration:

sudo apache2ctl configtest

If successful, reload Apache:

sudo systemctl reload apache2

Securing Your Server with HTTPS

In today’s digital landscape, securing your site with HTTPS is non-negotiable. You can achieve this using Let’s Encrypt, a free certificate authority. Here’s how to set it up:

  1. Install Certbot and the Apache plugin:

sudo apt install certbot python3-certbot-apache

  1. Request a Let's Encrypt certificate:

sudo certbot --apache -d example.com -d www.example.com

During this process, Certbot will automatically configure HTTPS and set up a renewal process.

Verifying Your SSL Certificate

To check your SSL certificate's status, run:

sudo certbot certificates

A successful response will confirm that your certificate is valid.

Conclusion

By following this guide, you have successfully installed the Apache web server on your Ubuntu machine, configured it to serve multiple domains, and secured it with HTTPS. This knowledge empowers you to manage your web hosting needs efficiently, whether on a local server or in the cloud. With the right setup, your Apache server will be ready to deliver excellent performance for your applications, ensuring a secure experience for your users.

Share this article:

Thomas Wells

About Thomas Wells

Izende Studio Web has been serving St. Louis, Missouri, and Illinois businesses since 2013. We specialize in web design, hosting, SEO, and digital marketing solutions that help local businesses grow online.

Need Help With Your Website?

Whether you need web design, hosting, SEO, or digital marketing services, we're here to help your St. Louis business succeed online.

Get a Free Quote