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
Installing Apache on Ubuntu 20.04
Installing Apache on Ubuntu 20.04
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software Apache
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install Apache on Ubuntu 20.04

Follow along with the steps below to install Apache on your system, and learn the basics of using the HTTP server. These steps will take place on the command line, so open a terminal to get started.

  1. Install Apache via apt package manager by executing the following commands.
    $ sudo apt update
    $ sudo apt install apache2
    
  2. 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
    

    SUBSCRIBE TO NEWSLETTER
    Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


    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
    
  3. 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
    
  4. You can test to make sure everything is working correctly by navigating to http://localhost on your system. You should be greeted by the default Apache page, as seen below.
  5. Default Apache page
    Default Apache page
  6. 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.html greeting 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.
  7. Accessing the web content we copied into the directory
    Accessing the web content we copied into the directory
  8. To setup SSL encryption using Let's Encrypt, install the certbot utility with the following command.
    $ sudo apt install certbot python3-certbot-apache
    
  9. 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
    

Closing Thoughts

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.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.