Install Apache in Ubuntu 16

This article is the first in a mini-series of quick reference guides for installing Apache, PHP, and MySQL in Ubuntu 16. These steps are possibly the minumum required for getting a development environment up and running, and can be used for testing your web development locally. This first article will cover the installation of the Apache HTTP Server.

There are many excellent guides availble which provide much more explanation. For a more detailed walkthrough of the process the below examples may be useful:

My environment for these steps is Ubuntu 16 running on VirtualBox in Windows 10 x64.

Install Apache HTTP Server in Ubuntu

  1. First we need to check if Apache httpd is already installed. There are a few different ways to do this. Here I’ll use apache2 -v to try check the Apache version. Check this StackOverflow question for another option using a package manager.

    Open a new terminal and type

    apache2 -v

    If Apache is not installed you will see an error message like this:

    "The program 'apache2' is currently not installed. You can install it by typing: sudo apt install apache2-bin"

  2. Now we can install the Apache web server

    sudo apt-get update
    sudo apt-get install apache2

    A small sidenote: you may have noticed the error message we got from apache2 -v indicated we should install apache2-bin, but instead we installed apache2 (without the -bin). Why is that?

    I wondered the same thing and found this SuperUser question: Difference between apache2 and apache2-bin. Basically, apache2-bin is just part of the overall Apache pacakge, so by installing apache2 we not only get apache2-bin, but a heap of other neccessary items.

  3. Open a web browser and navigate to localhost (or and you should see the Apache2 Ubuntu Default Page

    Apache It Works default page

    By default the Apache service will run automatically when Ubuntu starts.

  4. Apache was installed to the /etc/apache2 directory. We can cd into this folder and list the files:

    cd /etc/apache2
    ls -l

    Apache It Works default page

    This is also where Apache’s main configuration file apache2.conf can be found. Its full path is: /etc/apache2/apache2.conf

  5. We can also check Apache’s document root which by default is set as /var/www/html:

    cd /var/www/html
    ls -l

    Files placed in this location are accessible via the browser.

  6. This next step is not neccesary, but can be useful for final verification of the install. Create a new file within /var/www/html named test.html.

    Paste the below html into the file and save:

        <head><title>Apache test</title></head>
            <p1>Apache 2 web server - it works</p1>

    In your browser navigate to localhost/test.html (or and you should see the words Apache 2 web server - it works.

    Apache It Works default page

Wrapping up

That’s it for this quick article. In the next part we’ll install MySQL in Ubuntu.