Guide on how to install Apache on Ubuntu 18.04 – The Apache HTTP server is the most popular web server in the world. It is a free, open source and cross-platform HTTP server that provides powerful features that can be extended with a wide variety of modules.
The Apache HTTP Server project is an attempt 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 extensible server that provides HTTP services that conform to the current HTTP standard.
Apache HTTP Server (“httpd”) was launched in 1995 and has become the most popular web server on the Internet since April 1996. He celebrated his 20th birthday as a project in February 2015.
This guide describes how to install and manage an Apache web server on Ubuntu 18.04.
Before starting with this guide, make sure you are logged in as a user with sudo privileges. → How to Create a Sudo User and a Sudo Group on Ubuntu.
Apache is available in Ubuntu’s default repositories so we can easily install it using a package management tool
apt. On Ubuntu and Debian systems, the Apache package and its services are called
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 Apache service status with the following command:
$ sudo systemctl status apache2
Output 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
If your Ubuntu server is protected by a firewall, you will need to open the HTTP port (
80) and HTTPS (
Assuming you are using
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
Output 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 Apache Installation
To verify that everything is working properly, open it web browser You, type your server IP address
http://YOUR_IP_OR_DOMAIN/ and you will see Apache 18.04 Apache default 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
- The main Apache configuration file is
- The ports Apache will listen to are specified in
- 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
- To activate a virtual host, you need to create a symlink using the command
a2ensitefrom the configuration files found in the directory
sites-availableto the directory
sites-enabled. To disable virtual hosts use the command
- It’s a good idea to follow standard naming conventions. For example, if your domain name is
mydomain.comthen the virtual host configuration file must be named
- The configuration files which are responsible for loading various Apache modules are located in the directory
/etc/apache2/mods-available/. Configuration in directory
mod-availablecan be activated by creating a symlink to a directory
a2enconfand disabled by command
- Files containing global configuration fragments are stored in a directory
/etc/apache2/conf-available/. Files in directory
conf-availablecan be activated by symlinking it to
a2enconfand disabled by command
- 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 your domain’s document root directory to any location you want. The most common locations for webroots include:
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 your web or proxy server.
If you have any questions or feedback, feel free to leave a comment.