Logo

How to Install and Configure Apache on Ubuntu 24.04

Mar 15, 2024

To install and configure Apache on Ubuntu 24.04, follow these steps:

Step 1 : First, ensure your system's package index is up-to-date by running:

sudo apt update

Step 2 : Install the Apache web server with the following command:

sudo apt install apache2

Step 3 : Start and Enable Apache

sudo systemctl start apache2
sudo systemctl enable apache2

Step 4 : Check available application profiles with:

sudo ufw app list

Then allow Apache Full profile:

sudo ufw allow 'Apache Full'

Step 5 : Ensure Apache is running by checking its status:

sudo systemctl status apache2

Step 6 : Create a directory for your website, for example:

sudo mkdir /var/www/example.com

And create an index file:

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

In the text editor, add your HTML content for the homepage. For example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to Example.com</title>
</head>
<body>
    <h1>Welcome to Example.com!</h1>
</body>
</html>

Step 7 : Create a new virtual host configuration file for your domain:

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

Inside the text editor, add the configuration details for your domain. Here's an example of a basic configuration:

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

    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

Step 8 : Enable the site configuration with:

sudo a2ensite example.com.conf

Step 9 : Restart Apache to apply the changes:

sudo systemctl restart apache2

Step 10 : Visit your domain in a web browser to test your website.

Congratulations! You have successfully installed and configured Apache on Ubuntu 24.04.

Recommended