How to Install Apache HTTP Server
In this post I will write about how to install and configure Apache HTTP Server on Ubuntu 22.04 LTS
What is Apache HTTP Server
Apache HTTP Server, commonly known as Apache is cross-platform, open-source web server developed and maintained by the Apache Software Foundation.
Install Apache
Before moving forward, make sure you have sudo or root privileges.
After logging on our Ubuntu system we need to update the system packages with the help of the apt command.
sudo apt update

After the update process is completed, we can install the Apache2 package. In order to do this we need to run the following command:
sudo apt install apache2

After finishing the installation of Apache, make sure you open HTTP (port 80) and HTTPS (port 443) in order to allow traffic to the web server via the firewall. For UFW firewall run the following commands:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

You can check the ufw rules by running
sudo ufw status

Is Apache2 active/running?
With the help of some systemctl commands we can verify if the service is active.
sudo systemctl is-enabled apache2
sudo systemctl is-active apache2
sudo systemctl status apache2

Now open up a browser and type
http://localhost or http://server_ip
and you should be prompted by the Apache2 default page

Here are a couple of basic commands that will help you to manage the Apache2 server
content_copy
sudo systemctl enable apache2 -> enable service to start up at boot
sudo systemctl disable apache2 -> disable service to start at boot
sudo systemctl start apache2 -> start the server if it's stopped
sudo systemctl stop apache2 -> stop your webserver
sudo systemctl reload apache2 -> reload without dropping connections
sudo systemctl restart apache2 -> stop and start the service
Apache2 basic configuration
You will find all the configuration files for Apache2 in the /etc/apache2 directory, and you can see all the subdirectories and files by using
ls /etc/apache2

When running systemctl status apache2 after the installation, we got the following warning Jan 17 15:52:35 moshpit apachectl[8591]: AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message.
This will show up everytime we check the service status for apache2 if the FQDN is not set globally. What we need to do is to add the ServiceName directive in __/etc/apache2/apache2.conf.
Open up the file with your text editor of choice
sudo nano /etc/apache2/apache2.conf
and add
ServerName your.server.name/ server.ip.address/you.com

I have used 127.0.0.1 as I am running Apache on localhost.
After saving the file check the config syntax is correct using:
sudo apache2ctl configtest

This is it for now, in the following days I will continue with posts about Apache covering topics like how to install WordPress, MySQL, Virtual Hosts etc.
Thanks for reading.
