How to Install Apache on Ubuntu 16.04

r00t December 26, 2017

Install Apache on Ubuntu 16.04

In this tutorial we will show you how to install Apache on Ubuntu 16.04. We will also install and configure its prerequisites. Apache web server is among the most popular and powerful web servers in the world, as a result of its ease of administration and flexibility. In this tutorial we will install Apache on a host which doesn’t have a web server or database server installed.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache on Ubuntu 16.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Apache web server.

Installing Apache is as simple as running just one command:

sudo apt-get install apache2

For security purposes, you should prevent Apache from exposing files and directories within the web root directory /var/www/html to visitors:

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf

Start the Apache service and make it start on system boot:

sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 3. Configure Firewall for Apache.

Allow the default HTTP and HTTPS port, ports 80 and 443:

sudo apt-get install ufw
sudo ufw allow 'Apache Full'

Step 4. Apache Files and Directories.

Content:
  • /var/www/html: The actual website content, which by default, only consists of the default Apache page you found before, is served out of this / /var/www/html directory. This may be changed by altering Apache configuration files.
Server Configuration:
  • /etc/apache2: The Apache configuration directory. All the Apache configuration files live here.
  • /etc/apache2/apache2.conf: The primary Apache configuration file. This can be modified to create changes to the Apache International configuration. This file is responsible for loading many of the Additional files from the configuration directory.
  • /etc/apache2/ports.conf: This document specifies the ports That Apache will listen on. By default, Apache listens on port 80 and Additionally listens on port 443 when a module supplying SSL Abilities is enabled.
  • /etc/apache2/sites-available/: The directory where Per-site “Virtual Hosts” can be saved. Apache Won’t utilize the Configuration files found in this directory unless they are linked to the sites-enabled directory (see below). Usually, all Server block configuration is done within this directory, permitted By linking to another directory with the a2ensite command.
  • /etc/apache2/sites-enabled/: The directory where Empowered per-site “Virtual Hosts” are saved. Typically, these are made by connecting to configuration files found in the sites-available directory with the a2ensite. Apache reads the configuration files and hyperlinks found in this directory When it starts or reloads to compile a whole configuration.
  • /etc/apache2/conf-available/, /etc/apache2/conf-enabled/: These directories have the identical relationship as the sites-available and sites-enabled directories, but are used to keep configuration fragments which don’t belong in a Virtual Host. Files in the conf-available directory could be enabled with the a2enconf control and disabled using the a2disconf command.
  • /etc/apache2/mods-available/, /etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively. Documents in ending in .load include fragments to load certain modules, while files ending in. Conf contain the configuration for those modules. Modules can be enabled and disabled with the a2enmod and a2dismod command.

Congratulation’s! You have successfully install and configured Apache web server on your Ubuntu 16.04 server. Thanks for using this tutorial installing Apache on Ubuntu 16.04 LTS (Xenial Xerus) system.

The Tags:

Leave a Comment

Comments are closed.