Apache HTTP Server is a free and open-source cross-platform web server software. The goal of the Apache project is to provide a secure, efficient, and extensible server that provides HTTP services in sync with the current standards.
The new Apache 2.4.x or newer is needed in order to operate a TLS 1.3 web server with OpenSSL 1.1.1
In this tutorial, we will explain how to install the Apache web server on Ubuntu 22.04.
1. Update system repositories
The first thing to do is to make sure your system repositories are up to date in order to avoid running into errors at a later stage during the installation.
sudo apt update && apt upgrade -y
2. Install the Apache package.
Now that we have updated and upgraded our system, we now need to install Apache2 in our system with the following command:
sudo apt install apache2
Here apt will install apache2 with its dependencies.
#sample output Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 1,915 kB of archives. After this operation, 7,686 kB of additional disk space will be used. Do you want to continue? [Y/n] y
After the installation is complete, lets check the status of our Apache2 server.
To check the status of Apache2 server use the following command:
sudo systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese> Active: active (running) since Mon 2022-04-25 09:19:04 EAT; 5min ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 20151 (apache2) Tasks: 55 (limit: 9355) Memory: 5.3M CPU: 49ms CGroup: /system.slice/apache2.service ├─20151 /usr/sbin/apache2 -k start ├─20152 /usr/sbin/apache2 -k start └─20153 /usr/sbin/apache2 -k start Apr 25 09:19:04 zx-pc systemd: Starting The Apache HTTP Server... Apr 25 09:19:04 zx-pc apachectl: AH00558: apache2: Could not reliably de> Apr 25 09:19:04 zx-pc systemd: Started The Apache HTTP Server. lines 1-16/16 (END)
From the above output, the Apache web server started out successfully, but the best way to test out is to request a page from Apache itself.
In order to know the IP address of your server host, you can do the following on your terminal.
Here you will get some addresses to try out.
Another way is to use icanhazip tool which gives us the address also to use in our browser.
curl -4 icanhazip.com
3. Enable firewall
For good security practices, we need to enable a firewall in order to block unauthorized ports from accessing the system. Apache register itself with UFW upon installation. To list all available ufw profiles use the following command on your terminal.
sudo ufw app list Available applications: Apache Apache Full Apache Secure CUPS
Here we only need to allow traffic on Apache only, that is port 80. To allow so do the following:
sudo ufw allow "Apache"
Lastly, check the status again
sudo ufw status
4. Apache processes.
Whenever you are running apache, take into consideration the following processes, it will help you and save you time.
To start your web server
sudo systemctl start apache2
To stop web server
sudo systemctl stop apache2
To restart Apache web server
sudo systemctl restart apache2
To reload Apache web server
sudo systemctl reload apache2
To disable Apache web server
sudo systemctl disable apache2
To re-enable Apache after disabling it.
sudo systemctl enable apache2
This will allow Apache2 to start automatically on boot.
We have installed Apache2 successfully on Ubuntu 22.04. In case of any problem consult the Apache documentation.