How to Install Apache on Ubuntu 16.04 VPS

Introduction

Apache web server has a lion market share and is popularly known for serving millions of websites in the internet. The open http server is supported by most modern operating systems including Windows and Linux.

Apache works pretty well in Linux distributions and installing it on your Ubuntu 16.04 machine using the below steps  is a breeze.

Pre-requisites

Before installing Apache on Ubuntu 16.04, you should have a running VPS server. If you don’t have one purchase a $5 VPS plan from Digital Ocean , Vultr, or Linode.

These are the most reputable VPS providers that offer a $5 VPS plan bundled with 1GB guaranteed RAM, 1 core CPU, 20GB SSD storage and a monthly bandwidth of 1 Terabyte.

You should also have non-root username with sudo privileges and a command line tool such as Putty. However, some VPS providers have a free web-based CLI but you can use any tool.

Step 1: Install Apache

Ubuntu has a pretty simple package manager apt that allows us to virtually install any software from a central download repository. So let’s get started and install Apache.

First, update your system by typing the command below:

$ sudo apt update && sudo apt upgrade

Then, type the command below to Install Apache

$ sudo apt-get install apache2

Sudo will execute the above commands and display a confirmation message listing the Apache package that you intend to install together with the required disk space. To confirm the installation, press Y and  Enter  to proceed.

Step 2: Double check whether Apache was installed

Next we are going to spot check whether Apache was installed successfully. To do this, open a web-browser like Chrome, Mozilla or Windows Explorer and enter your VPS server public IP address  or domain name as shown below.

http://your_vps_server_IP_address

If the setup was completed without any hiccups, the default Ubuntu 16.04 Apache web page will be displayed as shown below. The page is for testing and information purposes.

 Step 3: Enabling basic Apache Modules

Installing Apache on your Ubuntu 16.04 Linux instance allows you to run different types of websites including blogs such as WordPress.  However, the basic modules required to run such websites are not enabled by default on Apache.

So let’s enable them.

Enabling Apache mod_rewrite on Ubuntu 16.04

This module is used to create pretty urls on a website. Enable it by typing the below command:

sudo a2enmod rewrite

Enabling Apache mod_deflate on Ubuntu 16.04

Consider enabling mod_deflate in all clean Apache installations. However, it might be enabled by default but it is good to double check. Mod_deflate saves you a lot of bandwidth because the module compresses output from your websites before it is sent to browsers.

To enable mod_deflate type the following command:

sudo a2enmod deflate

Enable mod_authz_host on Ubuntu 16.04

Mod_authz_host is used to control access to particular files on your VPS server. To enable it, run the following command:

sudo a2enmod authz_host

Enable Mod_headers on Apache

sudo a2enmod headers

Finally restart Apache to enable the changes above by typing the below Linux command:

sudo service apache2 restart

If you don’t get any errors, the above Apache modules were configured successfully.

Step 4: Understanding Apache Configurations

Now let’s master Apache’s directory structure. Remember, the more you familiarize yourself with the Apache settings, the better you will understand it.

Mastering Apache configuration files also makes troubleshooting easy because you exactly know where to go if something is not working on your server.

Apache web server is quite flexible and easy to configure. Thus, you can tweak your Apache instance by placing directives on plain text configuration files.

Here are the most basic files and directories that are used to configure your Apache web server on Ubuntu 16.04.

  1. /etc/apache2/apache2.conf: These file contains global settings for Apache 2
  2. /etc/apache2/conf-available: This directory contains all available configuration files.
  3. /etc/apache2/conf-enabled: The directory holds symbolic links to all files in the /etc/apache2/conf-available folder. When a symbolic link of configuration is created on this folder, it will be automatically loaded/enabled when Apache restarts.
  4. /etc/apache2/envvars: This file is used to set the Apache 2 environment variables.
  5. /etc/apache2/mods-available: It is an Apache 2 specific directory that holds modules together with their configurations. However, some modules may not have a configuration file.
  6. /etc/apache2/mods-enabled:  The directory stores symbolic links to the files in the ‘/etc/apache2/mods-available’ directory. When a symbolic link for a module is created in this directory, it will be enabled when Apache  restarts.
  7. /etc/apache2/ports.config: This file contains basic settings that direct Apache on which ports to listen to.
  8. /etc/apache2/sites-available: This is probably the most useful Apache directory, the folder holds all the settings for virtual hosts. Apache comes with a default virtual host named /etc/apache2/sites-available/000-default.conf. You can copy this file to create additional configurations for unlimited number of virtual hosts if you are hosting multiple sites on the same VPS server.
  9. /etc/apache2/sites-enabled: The directory holds symbolic links for /etc/apache2/sites-available directory. When a  website’s virtual host symbolic link  is created in this directory, the site will be enabled next time when Apache restarts.
  10. /etc/apache2/magic: This file contains instructions that determine the MIME type of a file.

Conclusion

Installing Apache on Ubuntu 16.04 is quite easy. Once you enable the necessary modules and understand the configuration directory structure, you will run your web server without any problems.

If you want to buy the best VPS hosts that can run your websites and web applications on Apache, I recommend Vultr , Digital Ocean or Linode. These cheap vps providers have a $5 vps host that is super affordable.

Remember to install Ubuntu 16.04 as your Operating System when you provision the server for the first time.

Ads by Google

Leave a Reply

Your email address will not be published. Required fields are marked *