Bobcares

How to Install Apache2 on Ubuntu 24.04 LTS

PDF Header PDF Footer

Learn how to install Apache2 on Ubuntu 24.04 LTS. Our Apache Support team is here to answer queries and concerns.

How to Install Apache2 on Ubuntu 24.04 LTS

 

How to Install Apache2 on Ubuntu 24.04 LTSApache 2 is a widely used and reliable web server available today. With the release of Ubuntu 24.04 LTS, it’s the perfect time to take advantage of its long-term support and install Apache2 for hosting web applications.

Today, we will walk through the complete process of installing, configuring, and securing Apache 2 on Ubuntu 24.04 LTS.

 

Prerequisites

Before starting, ensure that a server running Ubuntu 24.04 LTS and SSH access with administrative (sudo) privileges is available.

Step 1. Install Apache2 Web Server

First, log in to the Ubuntu server and install Apache2 using the following command:

sudo apt install apache2 -y

After the installation is complete, start the Apache service:

sudo systemctl start apache2

Next, check the status of the service:

sudo systemctl status apache2

We will see an output indicating that Apache2 is active and running:


apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running)

For managing Apache without service disruption, consider using a graceful restart method, especially on production environments.

Step 2. Create a Directory for Your Web Application

The default Apache document root is `/var/www/html`.

Now, let’s create a dedicated directory for the application:

sudo mkdir /var/www/html/myapp

Furthermore, assign ownership of the directory to the current user to avoid permission issues:

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

Step 3. Create a Simple Web Page

Go to the new web directory and create an HTML file:


cd /var/www/html/myapp
nano index.html

Then, paste the following HTML code:

<!DOCTYPE html>
<html>
<head>
<title>My Simple Web Application</title>
</head>
<body>
<h1>Welcome to My Web App!</h1>
<p>This is a simple web application running on an Apache server.</p>
</body>
<html>

Now, save and close the file.

Step 4. Configure Apache to Serve Your App

To have Apache serve the app either as the default site or under a custom domain, we need to create a new virtual host configuration:

sudo nano /etc/apache2/sites-available/myapp.conf

Now, add the following configuration:


<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myapp
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/myapp>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory&gt
</VirtualHost&gt

To enable the new virtual host:

sudo a2ensite myapp.conf

Now, reload and restart Apache to apply the changes:


sudo systemctl reload apache2
sudo systemctl restart apache2

Step 5. Configure Apache to Listen on Custom Ports

Apache listens on port 80 by default. To add another port like 8080:

sudo nano /etc/apache2/ports.conf

We can add or modify to include:


Listen 80
Listen 8080

To update the Virtual Host configuration:

sudo nano /etc/apache2/sites-available/000-default.conf

We can modify or add as seen below:


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

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

To restart Apache to apply new port settings:

sudo systemctl restart apache2
If your web application uses custom file types, ensure Apache is properly configured by adding custom MIME types to prevent issues with file downloads or media rendering.

Step 6. Configure Firewall Rules for Apache2

Now, we have to make sure that the firewall allows web traffic by enabling UFW:

sudo ufw enable

To allow Apache traffic (HTTP and HTTPS):

sudo ufw allow 'Apache Full'

We can verify UFW status by running this command:

sudo ufw status

We will see rules like:


Apache Full ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
If you are using Varnish Cache in your architecture, Apache can be configured to handle HTTPS traffic and terminate SSL before passing the request to Varnish. Learn how to set up Apache2 for SSL termination with Varnish for high-performance, secure web delivery.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Apache provides the flexibility and reliability needed for any web environment, from setting up the initial server to configuring virtual hosts and firewall rules.

In brief, our Support Experts demonstrated how to use Certbot with Linode DNS for automated SSL Certificates.

0 Comments

Submit a Comment

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

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!