sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Install Apache 2.4 on Ubuntu 22.04
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Install Apache 2.4 on Ubuntu 22.04

Samuel Siahaan
By Samuel Siahaan
Last updated: June 11, 2023
SHARE

Introduction

Apache HTTP Server, commonly referred to as Apache, is a powerful and widely used open-source web server software. Apache 2.4 is the latest version, boasting enhanced performance, security features, and scalability. If you’re running an Ubuntu 22.04, this comprehensive guide will take you through the step-by-step process of how to Install Apache 2.4 on Ubuntu 22.04. By following these instructions, you’ll have a robust foundation for hosting websites, applications, and more.

Contents
IntroductionTable of ContentsWhy Choose Apache 2.4?Installing Apache 2.4 on Ubuntu 22.04Step 1: Update System Packages on Ubuntu 22.04Step 2: Install Apache 2.4 on Ubuntu 22.04Step 3: Check Apache version on Ubuntu 22.04Step 4: Check Apache service on Ubuntu 22.04PHP application with Apache 2.4 web serverStep 5: Configure Firewall on Ubuntu 22.04Step 6: Test Apache Web ServerStep 7: Explore Apache ConfigurationStep 8: Setting Up Virtual Hosts in Apache2Step 9: Secure Your Website with HTTPS (Optional)Step 10: Optimize PerformanceConclusion

Table of Contents

  • Introduction
  • Why Choose Apache 2.4?
  • Installing Apache 2.4 on Ubuntu 22.04
    • Step 1: Update System Packages on Ubuntu 22.04
    • Step 2: Install Apache 2.4 on Ubuntu 22.04
    • Step 3: Check Apache version on Ubuntu 22.04
    • Step 4: Check Apache service on Ubuntu 22.04
    • Step 5: Configure Firewall on Ubuntu 22.04
    • Step 6: Test Apache Web Server
    • Step 7: Explore Apache Configuration
    • Step 8: Setting Up Virtual Hosts in Apache2
    • Step 9: Secure Your Website with HTTPS (Optional)
    • Step 10: Optimize Performance
  • Conclusion

Why Choose Apache 2.4?

Before we dive into the installation steps, let’s understand the benefits of Apache 2.4 and why it’s an excellent choice:

  1. Performance Improvements: Apache 2.4 introduces several performance enhancements, such as reduced memory usage and better handling of concurrent requests. This ensures smoother operations, even during high traffic periods.
  2. Enhanced Security: Security is a top priority. Apache 2.4 includes advanced security features like improved authentication and authorization modules, making it more resilient against cyber threats.
  3. Modular Architecture: Apache’s modular architecture allows you to add or remove modules as needed, optimizing the server for your specific use case.

Installing Apache 2.4 on Ubuntu 22.04

Follow these steps to install Apache 2.4 on your Ubuntu 22.04 and harness its powerful features for your web hosting needs:

Step 1: Update System Packages on Ubuntu 22.04

Begin by updating the package list to ensure you’re working with the latest software versions of your Ubuntu 22.04:

- Advertisement -
samm@apache:~$ sudo apt-get update
samm@apache:~$ sudo apt-get upgrade

This ensures your system is up-to-date before installing new software.

Step 2: Install Apache 2.4 on Ubuntu 22.04

With the package list updated, install Apache 2.4 using the following command:

samm@apache:~$ sudo apt install -y apache2

During installation, any required dependencies will also be installed automatically.

Step 3: Check Apache version on Ubuntu 22.04

Check for the currently active version of PHP on your Ubuntu 22.04 with the following command:

samm@apache:~$ apache2 -v
Server version: Apache/2.4.54 (Ubuntu)
Server built:   2023-06-08T15:59:07

Step 4: Check Apache service on Ubuntu 22.04

Once the installation is complete, Apache 2.4 on your Ubuntu 22.04 should be up and running. You can check its status using the following command:

- Advertisement -
samm@apache:~$ sudo systemctl status apache2
● apache2.service - Apache 2.4 HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-07-08 00:10:04 WIB; 1s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 31247 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 31276 (apache2)
      Tasks: 11 (limit: 9442)
     Memory: 22.8M
     CGroup: /system.slice/apache2.service
             ├─31276 /usr/sbin/apache2 -k start
             ├─31278 /usr/sbin/apache2 -k start
             ├─31279 /usr/sbin/apache2 -k start
             ├─31280 /usr/sbin/apache2 -k start
             ├─31281 /usr/sbin/apache2 -k start
             └─31284 /usr/sbin/apache2 -k start

Jul 08 00:10:04 app-vdam systemd[1]: Starting Apache 2.4 HTTP Server...
Jul 08 00:10:04 app-vdam systemd[1]: Started Apache 2.4 HTTP Server.

If the status shows “active (running),” it means Apache 2.4 on Ubuntu 22.04 has been successfully installed and is operational.

PHP application with Apache 2.4 web server

In Apache we can use a built-in module called mod_php to process PHP code directly within the Apache process.

But first you need to install Apache web server package, PHP, and Apache PHP, this time we use php version 7.4, you can use the other php versions.

- Advertisement -
samm@apache:~$ sudo apt install libapache2-mod-php7.4

Enable mod_php module:

samm@apache:~$ sudo a2enmod php7.4

Restart Apache web server after the configuration.

samm@apache:~$ sudo systemctl restart apache2

Step 5: Configure Firewall on Ubuntu 22.04

To allow external traffic to access your web server, you need to configure the firewall. Use ufw (Uncomplicated Firewall) to enable the necessary ports:

samm@apache:~$ sudo ufw allow http
samm@apache:~$ sudo ufw allow https
samm@apache:~$ sudo ufw reload

Or you can just allow “Apache Full”

samm@apache:~$ sudo ufw allow 'Apache Full'

The “Apache Full” profile allows both HTTP (port 80) and HTTPS (port 443) traffic.

Step 6: Test Apache Web Server

Open a web browser and enter your server’s IP address or domain name. If Apache 2.4 is functioning correctly, you should see the default Apache page.

The displayed output above provides confirmation of the successful installation and proper functioning of the Apache Web Server on Rocky Linux 9. Typically, basic Apache installations are designed to support single-page websites. For in-depth insights into setting up and deploying a Single Page Website in a production environment, we recommend exploring our comprehensive LAMP setup guide. Moving forward, the subsequent section delves into more advanced configurations within the Apache setup.

Step 7: Explore Apache Configuration

Apache’s configuration files are located in the /etc/apache2 directory. The main configuration file is apache2.conf, while site-specific configurations are stored in the sites-available and sites-enabled directories. To make changes to the configuration, use a text editor:

samm@apache:~$ sudo vi /etc/apache2/apache2.conf

Remember to restart Apache after making configuration changes:

samm@apache:~$ sudo systemctl restart apache2

Step 8: Setting Up Virtual Hosts in Apache2

Create the directory for your_domain as follows:

samm@apache:~$ sudo mkdir /var/www/sammlinux

Next, assign ownership of the directory to the user you’re currently signed in as with the $USER environment variable:

samm@apache:~$ sudo chown -R $USER:$USER /var/www/sammlinux

To ensure that your permissions are correct and allow the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, you can input the following command:

samm@apache:~$ sudo chmod -R 755 /var/www/sammlinux

Next, create a sample index.html page using vim editor:

samm@apache:~$ sudo vi /var/www/sammlinux/index.html

Inside, add the following sample HTML:

<html>
    <head>
        <title>Welcome to sammlinux!</title>
    </head>
    <body>
        <h1>Success!  Welcome to sammlinux. And its working</h1>
    </body>
</html>

Save and close the file when you are finished.

Make a new one at /etc/apache2/sites-available/sammlinux.conf:

samm@apache:~$ sudo vi /etc/apache2/sites-available/sammlinux.conf

Add in the following configuration block, which is similar to the default, but updated for your new directory and domain name:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName sammlinux.com
    ServerAlias www.sammlinux.com
    DocumentRoot /var/www/sammlinux
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file when you are finished.

Now enable the file with the a2ensite tool:

samm@apache:~$ sudo a2ensite sammlinux.conf

Disable the default site defined in 000-default.conf:

samm@apache:~$ sudo a2dissite 000-default.conf

Next, test for configuration errors:

samm@apache:~$ sudo apache2ctl configtest

You should receive the following output

. . .
Syntax OK

Restart Apache to implement your changes:

samm@apache:~$ sudo systemctl restart apache2

You can test this by navigating to http://sammlinux.com

Step 9: Secure Your Website with HTTPS (Optional)

For secure data transmission, consider setting up HTTPS using SSL/TLS certificates. You can use Let’s Encrypt to obtain free SSL certificates.

Step 10: Optimize Performance

To further optimize Apache’s performance, you can adjust various settings. For instance, you can adjust the KeepAlive timeout to manage how long a connection is kept open:

samm@apache:~$ sudo vi /etc/apache2/apache2.conf

Inside the file, modify the KeepAliveTimeout value according to your requirements.

Conclusion

Installing Apache 2.4 on your Ubuntu Server 22.04 opens the door to a world of powerful web hosting capabilities. Following this step-by-step guide ensures a seamless installation process, granting you access to enhanced performance, security, and scalability. With Apache 2.4 as your web server, you’re poised to provide a robust and secure environment for hosting websites, applications, and services. Embrace the power of Apache 2.4 and propel your online presence to new heights.

Also Read Our Other Guides :

  • How To Install Apache on Rocky Linux 9
  • How To Install Apache Web Server on CentOS 7
  • How To Install Nginx on Ubuntu 22.04: A Comprehensive Guide
  • How To Install PHP 7.4 on Ubuntu 22.04
  • How To Install MariaDB 10.6 on Ubuntu Server 22.04

Finally, now you have learned how to Install Apache on Ubuntu on your Ubuntu 22.04 Server.

TAGGED:ApacheLampUbuntuWebserver

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Install Nextcloud with Apache and MariaDB on Ubuntu Server 22.04
Next Article How To Install Redis on Ubuntu Server 22.04
Leave a Comment

Leave a Reply Cancel reply

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

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Debian

How To Build NGINX from Source (Compile) on Debian 11

12 Min Read
Ubuntu

How To Install Python 3.11 from Source on Ubuntu 22.04

10 Min Read
CentOS

How To Install RTMP Server with Nginx on CentOS 7

14 Min Read
Ubuntu

How To Install MariaDB 10.6 on Ubuntu Server 22.04

14 Min Read
CentOS

How To Install PHP 8.2 on CentOS 7 / RHEL 7

18 Min Read
CentOS

How To Install Apache Web Server on CentOS 7

11 Min Read
Debian

How To Install Nginx on Debian 11: A Comprehensive Guide

9 Min Read
Ubuntu

How To Install DBeaver Community on Ubuntu 22.04

7 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?