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.
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 .
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
First, update the package index and then install the package
apache2with 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
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-06-24 02:17:57 PDT; 2min 41s ago
Main PID: 3143 (apache2)
Tasks: 55 (limit: 2321)
|-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 must open HTTP (
80) and HTTPS (
443) ports .
Assuming you are using it
UFWto 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
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
- The main Apache configuration file is
- The ports that 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 enable virtual hosts, you need to create a symlink by using commands
a2ensitefrom the configuration file found in the directory
sites-availableto the directory
sites-enabled. To disable the virtual host use the command
- It is a good idea to follow the standard naming convention. For example, if your domain name is
mydomain.comthen the virtual host configuration file must be named
- The configuration file responsible for loading various Apache modules is in the directory
/etc/apache2/mods-available/. Configuration in the directory
mod-availablecan be activated by creating a symlink to the directory
/etc/apache2/mods-enable/with the command
a2enconfand deactivated with the command
- Files containing global configuration fragments are stored in the directory
/etc/apache2/conf-available/. Files in the directory
conf-availablecan be activated by creating a symlink to
/etc/apache2/conf-enabled/with the command
a2enconfand deactivated with the command
- 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:
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.