On this short tutorial, we will learn how to install Apache Web Server on Ubuntu 18.04 LTS operating system.
Introduction
When we have our own business, especially small and medium enterprises (SMEs), having our own website is a strategic decision in developing our business in the future. Because our products will be easily recognized by our customers or potential customers, that way we have a great opportunity with a minimum budget to market or promote our products. Without having to have expert level knowledge, we can start building our website using open source applications that are already available on the internet. To create our own website, we need a web server that can provide services for our website management.
The function of web server is to display our website’s content by storing, processing and delivering webpages to users. Usually, the web server uses the HTTP (Hyper Text Transfer Protocol) as an exchange of data between the client (users) and our server. Besides HTTP, web servers also support SMTP (Simple Mail Transfer Protocol) and FTP (File Transfer Protocol) used for email, file transfer and storage. Apache is very popular web server. It is used by various groups around the world. From small companies to enterprise level. Well, in this article, we will discuss how to install Apache Web Server on the Ubuntu 18.04 LTS operating system.
Apache Web Server Installation
Before we start the installation, there are prerequisites that must be met. Some of the basic requirements that must be met including :
- An Ubuntu 18.04 system with sufficient disk space
- non-root user with sudo privileges configured on your server.
- Good internet connection to download repository/source files.
The Apache web server installation process will be explained in detail in the sub-chapters below.
- Installing Apache Web Server
- Adjusting Firewall
- Checking WebServer
- Apache Web Server Process Management
Installing Apache Web Server
By default Apache Web server has been included on Ubuntu 18.04 LTS repository. The first step, we will begin by updating the local package index to reflect the latest version.
1. Update Ubuntu 18.04 LTS Repository
Updating Ubuntu system by submitting command line :
# apt update
The output will be shown below :
root@ubuntu:~# apt update Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Get:4 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [38.6 kB] Get:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:6 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 48x48 Icons [17.6 kB] Get:7 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [295 kB] Get:8 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 64x64 Icons [41.5 kB] Get:9 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [42.0 kB] Get:10 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 48x48 Icons [16.4 kB] Get:11 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 64x64 Icons [116 kB] Get:12 http://us.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 48x48 Icons [76.1 kB] Get:13 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B] Get:14 http://us.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 64x64 Icons [147 kB] Get:15 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [254 kB] Get:16 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 48x48 Icons [198 kB] Get:17 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 64x64 Icons [441 kB] Get:18 http://us.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B] Get:19 http://us.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [7,916 B] Fetched 1,948 kB in 31s (61.9 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done
2 Installing Apache Web Server
After updating system is completed done, the next step is to install Apache Web Server by submitting command line :
# apt install apache2
The output will be shown below :
root@ubuntu:~# apt install apache2 Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libllvm8 Use 'apt autoremove' to remove it. The following additional packages will be installed: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap 0 upgraded, 8 newly installed, 0 to remove and 29 not upgraded. Need to get 1,604 kB of archives. After this operation, 6,493 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libapr1 amd64 1.6.3-2 [90.9 kB] Get:2 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1 amd64 1.6.1-2 [84.4 kB] Get:3 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-2 [10.6 kB] Get:4 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-ldap amd64 1.6.1-2 [8,764 B] Get:5 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-bin amd64 2.4.29-1ubuntu4.11 [1,071 kB] Get:6 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-utils amd64 2.4.29-1ubuntu4.11 [83.9 kB] Get:7 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-data all 2.4.29-1ubuntu4.11 [160 kB] Get:8 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.11 [95.1 kB] Fetched 1,604 kB in 25s (64.9 kB/s) Selecting previously unselected package libapr1:amd64. ...
3 Verifying Apache Web Server Version
After installation was finished, then we will verity Apache version by submitting command line :
# apache2 -version
Output :
root@ubuntu:~# apache2 -version Server version: Apache/2.4.29 (Ubuntu) Server built: 2019-09-16T12:58:48
Adjust Firewall
After Apache Web server installation was completed done, then we have to allow outside access to the default web ports. For this purpose we have to modify the firewall setting on our system, it has been provided a tools called as UFW. We can list the ufw
application profiles by typing :
# ufw app list
output of this command line is shown below :
root@ubuntu:~# ufw app list Available applications: Apache Apache Full Apache Secure CUPS
From the output, we can discover if there are three profiles type for Apache on this environment, namely :
- Apache: This profile opens only port 80 (normal, unencrypted web traffic)
- Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
- Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
Mostly, we have to enable Apache profiles to serve outside connection to our Apache Web Server service, by submitting command line :
# ufw allow 'Apache'
output will be as shown below :
root@ubuntu:~# ufw allow 'Apache' Rules updated Rules updated (v6)
Then we can verify it by querying it status, by submitting command line :
# ufw status
output will e shown below :
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Apache ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6)
Verifying Web Server Services
After setting the Firewall on the server, we will verify whether the web server service is running normally or not. For this purpose, we will check the Apache service status with the command line.
# systemctl status apache2
output will be shown below :
root@ubuntu:~# systemctl status apache2 ? 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 Tue 2019-10-08 23:24:09 PDT; 9min ago Main PID: 3617 (apache2) Tasks: 55 (limit: 5373) CGroup: /system.slice/apache2.service +-3617 /usr/sbin/apache2 -k start +-3620 /usr/sbin/apache2 -k start +-3621 /usr/sbin/apache2 -k start Oct 08 23:24:09 ubuntu systemd[1]: Starting The Apache HTTP Server... Oct 08 23:24:09 ubuntu apachectl[3606]: AH00558: apache2: Could not reliably determine the server's fully qualified domain Oct 08 23:24:09 ubuntu systemd[1]: Started The Apache HTTP Server. lines 1-15/15 (END)
We can also do testing via a web browser by typing the IP address or hostname where our web server is installed.
http://ip_address_server
Apache Web Server Process Management
At this stage, we already have the Apache Web Server running on our system. Henceforth, we can make settings to the Apache service. We can do startup, stop, reload, enable and disable Apache Services.
To start the web server when it is stopped, use the command line :
~# systemctl start apache2
To stop your web server, use the command line :
~# systemctl stop apache2
To stop and then start the service again, use the command line :
~# systemctl restart apache2
If you are simply making configuration changes, Apache can often reload without dropping connections. use the command line:
~# systemctl reload apache2
By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by typing:
~# systemctl disable apache2
To re-enable the service to start up at boot, use the command line:
~# systemctl enable apache2
Conclusion
This article explains how to install Apache Web Server with Ubuntu 18.04 system. I hope, this article can be useful for people who are looking for it.