How to Install Apache on Ubuntu 22.04

Install Apache on Ubuntu 22.04

In this article, we will have explained the necessary steps to install Apache on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Apache HTTP server is the most widely used web server software. Developed and maintained by Apache Software Foundation. Dynamically loadable modules, management of static files, and easy integration with other applications are a few fantastic features of Apache Web Server. Apache also offers a secure file-sharing feature that permits users to store their important files in its root directory and share them with other users.

Prerequisite:

  • Operating System with Ubuntu 22.04
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install Apache on Ubuntu 22.04 LTS

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common dirmngr apt-transport-https

Step 2. Install Apache Web Server on Ubuntu Linux.

Installing the Apache on your Ubuntu 22.04 Jammy Jellyfish system is straightforward, Now, execute the following command on the command line or terminal to download and install the Apache web server on the Ubuntu system:

sudo apt install apache2

After you have successfully installed Apache, you now need to enable, start and check the status it using the following command:

sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2

Step 3. Configure UFW Firewall.

Since the UFW firewall runs by default on Ubuntu 22.04, you can easily enable the connection using the following command:

sudo ufw allow 'Apache Full'
sudo ufw enable

Check the status of UFW:

sudo ufw status

Step 4. Accessing the Nginx Web UI.

Once the Apache web server is installed and set up properly. You can use the following address in the browser to check whether Nginx is running or not:

http://your-ip-address

Install Apache on Ubuntu 22.04 LTS

Step 5. Set up Apache virtual hosts on Ubuntu 22.04.

Now create the directory for your website or domain as follows:

sudo mkdir /var/www/example.com

Next, changing the ownership of the “example.com” directory with the “www-data” environment variable:

sudo chown -R www-data:www-data /var/www/example.com

After that, create a sample index.html page using your favorite editor:

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

Add the following file:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file and restart the Apache service:

sudo a2ensite example.com
sudo systemctl start apache2

That’s all you need to do to install Apache on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installation of the Apache web server, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.