How to install the Apache web server on Ubuntu linux
If you’re reading this, you probably already know that Apache is one of the most popular web servers. It’s definitely my top choice for many reasons, but mostly due to the fact that it supports dynamically loaded modules and integration with other software such as PHP.
Let’s get started. This will work as root, but you should ideally have a non-root user with sudo privileges.
Install Apache 2
Apache is readily available in many Linux distributions’ default repositories, including Ubuntu.
Connect to your server with SSH and run the following commands:
sudo apt-get update sudo apt-get install apache2
This will install Apache and its required dependencies.
I highly suggest installing the ufw firewall before proceeding, if you don’t already have it installed.
Assuming you install the firewall, you will now need to allow access through the firewall for Apache.
You can type the following command to check available application profiles
sudo ufw app list
It should include the following list:
Available applications: Apache Apache Full Apache Secure
- Apache profile allows only port 80
- Apache Full allows port 80 and port 443
- Apache Secure allows only port 443
Port 80 is unencrypted web traffic, and 443 is TLS/SSL encrypted traffic.
By default, Apache will only be running on port 80. But I recommend setting up and using SSL, which I’ll cover in another post!
With that said, you should now type the following (in preparation for SSL)
sudo ufw allow 'Apache Full'
Assuming all went well, that’s really all it takes to get Apache running the default server on port 80!
You can test it out by navigating to your server’s IP, such as http://127.0.0.1 if you’re installing it on your local machine – but you probably using a remote server, so you should use its public IP.
What’s next?
You will most likely want to set up virtual hosts so that the web server can serve different sites for each domain.