Apache HTTP Server is the most popular web server in the world. This is a free, open-source, and cross-platform HTTP server that provides advanced features that can be expanded with a variety of modules.
The Apache HTTP Server project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The aim of this project is to provide a secure, efficient and expandable server that provides HTTP services that are in line with current HTTP standards.
Apache HTTP Server (“httpd”) was launched in 1995 and has been the most popular web server on the Internet since April 1996. He celebrated his 20th birthday as a project in February 2015.
This guide explains how to install and manage an Apache web server on Ubuntu 18.04.
Requirements
Before starting with this guide, make sure you are logged in as a user with sudo privileges. → How to create a Sudo User and Sudo Group on Ubuntu .
Install Apache
Apache is available in Ubuntu’s default repository so we can easily install it using a package management tool apt
. On Ubuntu and Debian systems, the Apache package and its service are called apache2
.
First, update the package index and then install the package apache2
with the following command:
sudo apt update
sudo apt install apache2
And that’s it, Apache is installed and automatically started. You can check the status of the Apache service with the following command:
sudo systemctl status apache2
1 2 3 4 5 6 7 8 9 10 11 |
apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d `-apache2-systemd.conf Active: active (running) since Sun 2018-06-24 02:17:57 PDT; 2min 41s ago Main PID: 3143 (apache2) Tasks: 55 (limit: 2321) CGroup: /system.slice/apache2.service |-3143 /usr/sbin/apache2 -k start |-3144 /usr/sbin/apache2 -k start `-3145 /usr/sbin/apache2 -k start |
Adjust Firewall
If your Ubuntu server is protected by a firewall, you must open HTTP ( 80
) and HTTPS ( 443
) ports .
Assuming you are using it UFW
to manage your firewall, you can open the required ports with the following command:
sudo ufw allow 'Apache Full'
You can verify changes by:
sudo ufw status
1 2 3 4 5 6 7 8 |
Status: active To Action From -- ------ ---- 22/tcp ALLOW Anywhere Apache Full ALLOW Anywhere 22/tcp (v6) ALLOW Anywhere (v6) Apache Full (v6) ALLOW Anywhere (v6) |
Verifying the Apache Installation
To verify that everything is functioning correctly, open your web browser, type the IP address of your server http://YOUR_IP_OR_DOMAIN/
and you will see the default Apache 18.04 Apache welcome page as shown in the image below:
This page includes some basic information about Apache configuration files, helper scripts, and directory locations.
Apache Configuration File Structure and Best Practices
- All Apache configuration files are located in the directory
/etc/apache2
. - The main Apache configuration file is
/etc/apache2/apache2.conf
. - The ports that Apache will listen to are specified in
/etc/apache2/ports.conf
. - Apache Virtual Hosts files are stored in a directory
/etc/apache2/sites-available
. The configuration files found in this directory are not used by Apache unless they are linked to the directory/etc/apache2/sites-enabled
. - To enable virtual hosts, you need to create a symlink by using commands
a2ensite
from the configuration file found in the directorysites-available
to the directorysites-enabled
. To disable the virtual host use the commanda2dissite
. - It is a good idea to follow the standard naming convention. For example, if your domain name is
mydomain.com
then the virtual host configuration file must be named/etc/apache2/sites-available/mydomain.com.conf
. - The configuration file responsible for loading various Apache modules is in the directory
/etc/apache2/mods-available/
. Configuration in the directorymod-available
can be activated by creating a symlink to the directory/etc/apache2/mods-enable/
with the commanda2enconf
and deactivated with the commanda2disconf
. - Files containing global configuration fragments are stored in the directory
/etc/apache2/conf-available/
. Files in the directoryconf-available
can be activated by creating a symlink to/etc/apache2/conf-enabled/
with the commanda2enconf
and deactivated with the commanda2disconf
. - The Apache log files (access.log and error.log) are located in the directory
/var/log/apache/
. It is recommended to have different access and error log files for each vhost. - You can set the root directory of your domain’s document to the location you want. The most common locations for webroots include:
/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
Conclusion
You have successfully installed Apache on your Ubuntu 18.04 linux server. You are now ready to start deploying your application and use Apache as a web or proxy server.