Apache is one of the most popular and longstanding HTTP servers. It’s an open-source and cross-platform web server software developed and maintained by Apache Software Foundation. It’s easy to set up and learn to use, which has led to its widespread adoption for small and large scale websites.
In this guide, we’ll go over the step by step instructions to install Apache on Ubuntu 20.04 Focal Fossa.
In this tutorial you will learn:
- How to install Apache web server on Ubuntu 20.04
- How to control Apache web server with systemctl commands
- How to open firewall for HTTP (port 80) and HTTPS (port 443)
- How to host a website with Apache
- How to install SSL certificate with Let’s Encrypt
|Category||Requirements, Conventions or Software Version Used|
|System||Installed or upgraded Ubuntu 20.04 Focal Fossa|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Install Apache on Ubuntu 20.04
- Install Apache via apt package manager by executing the following commands.
$ sudo apt update $ sudo apt install apache2
- Once it’s installed, you can use systemd’s systemctl commands to control the service.
Enable or disable Apache from starting at system boot:
$ sudo systemctl enable apache2 OR $ sudo systemctl disable apache2
Start or stop Apache web server:
$ sudo systemctl start apache2 OR $ sudo systemctl stop apache2
We have a separate guide to explain the difference between restarting or reloading the Apache service on Ubuntu 20.04.
$ sudo systemctl restart apache2 OR $ sudo systemctl reload apache2
- If you are using ufw firewall on your system, you’ll need to allow port 80 for HTTP traffic and 443 for HTTPS if you plan to use SSL. This will allow outside traffic to access your website.
$ sudo ufw allow http AND (if applicable) $ sudo ufw allow https
- You can test to make sure everything is working correctly by navigating to
http://localhoston your system. You should be greeted by the default Apache page, as seen below.
- With Apache up and running, we’re ready to configure our website. The default directory for our website’s files is
/var/www/html. Move your files here, or begin by replacing the default
index.htmlgreeting page. In this example, we’ll just make a simple HTML document to see the changes reflected on the website.
$ echo Apache on Ubuntu 20.04 > index.html $ sudo mv index.html /var/www/html
To learn more about virtual hosts, which allows you to host multiple websites or change the configuration of your current one (such as the directory where files are stored, domain name, as well as the error logs, etc), check our guide on Apache virtual hosts explained.
- To setup SSL encryption using Let’s Encrypt, install the certbot utility with the following command.
$ sudo apt install certbot python3-certbot-apache
- Configure the SSL certificate by executing the following command and going through the prompts that pop up. The last question will ask you if you want to redirect HTTP requests straight to HTTPS. It’s recommended that you opt for this. Obviously, for this to work the domain must point correctly to our publicly accessible server IP.
$ sudo certbot --apache
In this guide, we saw how to install Apache on Ubuntu 20.04 Focal Fossa. We also learned how to control the Apache service via systemd, configure the firewall to allow outside traffic, begin setting up a website, and obtain an SSL certificate through Let’s Encrypt.
This will be enough to get you started hosting a basic website. Many modern websites also utilize other web technologies like PHP or a database. These modules are easily installed alongside Apache, and the software can be downloaded from Ubuntu’s package manager. To setup a content management system and deploy a polished website in minutes, check out our guide on WordPress installation with Apache on Ubuntu 20.04.