Install Apache on Ubuntu 18.04

In this post, I will show you how to install Apache Ubuntu 18.04.  Apache Web Server is one of the most utilized open source web servers available.

The first thing you need to make sure you do is have Ubuntu 18.04 fully installed and updated.

# apt update && apt upgrade -y

Once the updates are complete go ahead and reboot.

Installing Apache Web Server

Now that everything is updated we need to install the packages for Apache.

# apt install apache2

This will install the basic Apache 2 Web Server.

All of your HTML files will be located in /var/www/html.  The default installation comes with a default HTML file and you can browse to it to ensure that everything is working:

http://{your server ip}

You should see this web page:

install apache ubuntu 18.04

At this point your web server is installed.  However, if you would like to add some security to your site keep reading.

Configuring HTTPS

In order to server your web pages securely, you will need to setup HTTPS.  You will need to get SSL certificates in order to accomplish this.  There are a couple of ways of getting SSL certificates.  If you site is going to be a publicly accessible web site then you should probably spring a few bucks and buy SSL certs.  One site I like to recommend is the SSL Store which has pretty good deals.  They have pretty good instructions on how to install the SSL certs and configure HTTPS so I will not cover that here.

The second option is self-signed certificates.  These you create on your web server and use to deploy HTTPS.  This isn’t as secure as the first option but is great for testing or running internal web sites.  I will cover this process in this section.

The first thing we need to do is generate our certificates.

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt

It will ask you several questions.  You can either accept the defaults (which are empty) or enter in the information.  Now we need to tell Apache to serve HTTPS traffic on port 443 (the standard HTTPS port) and use our newly created SSL certificates.

Next we need to modify the default SSL file /etc/apache2/sites-available/default-ssl.conf using our favorite editor (EMACS I hope) and update it to appear like below:


        <IfModule mod_ssl.c>
            <VirtualHost _default_:443>
                ServerAdmin [email protected]

                DocumentRoot /var/www/html

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile    /etc/ssl/certs/selfsigned.crt
                SSLCertificateKeyFile /etc/ssl/private/selfsigned.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                                SSLOptions +StdEnvVars

The key parts are the SSLCertificateFile and SSLCertificateKeyFile which point to the SSL certs we created earlier. Save the file and exit.

Now we need to enable HTTPS.

# a2enmod ssl
# a2enmod headers
# a2ensite default-ssl

Now restart Apache to make the changes take affect.

Browse to https://{your server ip} and you should see the same default web page as before.  You will have to click through a warning from your browser first.

That’s all there is to it.  This is a very basic HTTPS installation and you can tighten the security more.

Click here for more great articles from AdminTome Blog.


I hope you have enjoyed this article, if so please leave a comment below.  For more articles, please signup for the AdminTome Blog below.  Also please feel free to share the article to your friends using the buttons to the left.  Thanks again for reading this post.