Apache on Ubuntu Server

Apache is a popular web server and a part of the LAMP-stack, which you can read about at IBM.

Let’s start by updating the package manager cache, run the command “sudo apt update

Install Apache by running the command “sudo apt install apache2
Write “y” to continue

Apache is now installed, but we need configure the firewall to allow HTTP traffic. Start by listing all available applications by running the command “sudo ufw app list

To allow traffic on port 80, run the command “sudo ufw allow ‘Apache’” and verify the change with the command “sudo ufw status
If the firewall is inactive, run the command “sudo ufw enable

(Apache Full will allow unencrypted traffic on port 80 and encrypted traffic on port 443, while Apache Secure only allows encrypted traffic on port 443)

Check if the web server is up and running with the command “sudo systemctl status apache2
If it is inactive, run the command “sudo systemctl start apache2


Add a port forwarding rule to the virtual machine for the quickest and easiest way to get access to Apache web server from your host machine.
Shutdown Ubuntu Server with the command “init 0

In the VirtualBox Manager, right-click on your Ubuntu Server and choose “Settings

Then click on “Network

Click on “Advanced” and then “Port Forwarding

Click on the green + button to add a new port forwarding rule

Give the rule a name, and then add “80” under both “Host Port” and “Guest Port” then click “OK”, and “OK” again before starting up the Ubuntu Server

Check that Apache is running with the command “sudo systemctl status apache2

Then open a browser on your host machine and go to http://localhost/

Apache is now installed and ready for configuration, check out the official Apache HTTP Server Documentation here

Sources

IBM: https://www.ibm.com/topics/lamp-stack
Apache HTTP Server Documentation: https://httpd.apache.org/docs/2.4/
All images: Solberg, 2022