Installing the Apache Server on Ubuntu Version 16.04
The Apache HTTP server is one of the leading web servers in the world. It comes with several powerful features along with dynamically loadable modules, reliable media support, and extensive integration with other leading software.
Steps to Install the Apache Web Server on Ubuntu version 16.04:
Apache is available with Ubuntu's default software repositories, so it can be installed using conventional package management tools.
You can begin by updating the local package index to reflect the recent upstream modifications. Later you can install the apache2 package:
sudo apt-get update
sudo apt-get install apache2
After the confirmation of installation, apt-get will install the Apache and all the required dependencies
2) Adjust the Firewall
Before testing the Apache, you have to modify the firewall to permit outside access to the default web ports and you need to have a UFW firewall configured to restrict the access to the server.
You will be able to list the ufw application profiles by typing the below command:
sudo ufw app list
You need to get the listing of the application profiles:
There are three profiles available for Apache like Apache, Apache Full, Apache Secure.
For this purposes, you can allow the incoming traffic for the Apache Full profile by typing the below query:
sudo ufw allow 'Apache Full'
You will be able to verify the modification by typing:
sudo ufw status
You should be able to see HTTP traffic permitted in the displayed output:
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)
3) Checking your Web Server
During the end of the installation process, Ubuntu 16.04 will begin Apache. But the web server will already be up and running.
You will be able to check with the systemd init system to ensure the service is running by typing the below command:
sudo systemctl status apache2
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Active: active (running) since Sat 2018-03-01 17:25:06 UTC; 2h 10min ago
Process: 4336 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 4359 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
├─4374 /usr/sbin/apache2 -k start
├─4377 /usr/sbin/apache2 -k start
└─4378 /usr/sbin/apache2 -k start
March 01 17:25:05 ubuntu-512mb-nyc3-01 systemd: Stopped LSB: Apache2 web server.
March 01 17:25:05 ubuntu-512mb-nyc3-01 systemd: Starting LSB: Apache2 web server...
March 01 17:25:05 ubuntu-512mb-nyc3-01 apache2: * Starting Apache httpd web server apache2
March 01 17:25:05 ubuntu-512mb-nyc3-01 apache2: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 000.0.0.0. Set the 'ServerName' directive globally to suppress this message
March 01 17:25:05 ubuntu-512mb-nyc3-01 apache2: *
March 01 17:25:05 ubuntu-512mb-nyc3-01 systemd: Started LSB: Apache2 web server.
You can try by typing the below query at the server's command prompt:
You will be provided with numerous of addresses separated by spaces. You can also try each in your web browser to know whether they are performing.
4) Managing the Apache Process
Now you will be having your web server up and running, you can go over some basic commands.
To stop your web server, you need to type:
sudo systemctl stop apache2
To begin the web server when it has been stopped, type:
sudo systemctl start apache2
To stop and then begin the service again, type:
sudo systemctl restart apache2
If you are making any configuration changes, Apache will be able to reload often without dropping the connections. To perform this, you can use the below command:
sudo systemctl reload apache2
To re-enable the service to begin from the boot, you need to type:
sudo systemctl enable apache2
Apache will now be able to start automatically when the server boots again.
5) Getting familiar with important Apache Files and Directories
/var/www/html: It is the actual web content, by default only consists of the default Apache page you have seen previously. It is served out of the /var/www/html directory. It can be changed by modifying the Apache configuration files.
/etc/apache2: All kind of Apache configuration files reside here.
/etc/apache2/apache2.conf: It is the main Apache configuration file. It can be altered to make changes in the Apache global configuration. This file is responsible for loading numerous of the different files in the configuration directory.
/var/log/apache2/access.log: As a default, each and every request to the web server is recorded in this log file until Apache is configured to perform.
/var/log/apache2/error.log: As a default, all the errors are recorded in this file. The LogLevel directive in the Apache configuration specifies how much information the error logs consists.