How to install Apache Webserver in Ubuntu Linux 18.04

Posted on


This article presents how to install Apache Webserver in Ubuntu Linux 18.04. The way for installing it is very easy. Performing the installation is possible by executing certain command in the command line.

But first of all, check whether the Apache Webserver exist in the package repository by typing the following command :

apt search --names-only ^.*apache.*$

If there is a package with the name of ‘apache’, the following output will appear :

user@hostname:~$ apt search --names-only ^.*apache.*$
Sorting... Done
Full Text Search... Done
apache2/bionic-updates,now 2.4.29-1ubuntu4.5 amd64 [installed]
  Apache HTTP Server


Another alternative command for searching the package contain the keyword ‘apache’ exists as follow :

apt-cache search --names-only ^.*apache.*$

The command output for the above command execution is in the following lines :

user@hostname:~$ apt-cache search --names-only ^.*apache.*$
apache2 - Apache HTTP Server

Since the ‘apache’ package is actually exist, the next step is to check whether it is already installed or not. Just execute the following command for checking the existance in the operating system :

apt list --installed | grep apache2

The following is the output of the above command :

user@hostname:~$ apt list --installed | grep apache2

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

apache2/bionic-updates,now 2.4.29-1ubuntu4.5 amd64 [installed]
user@hostname:~$ apt list --installed | grep apache2

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.


Since the package with the name of ‘apache2’ is not exist in the operating system, just continue on to the installation process.


The installation process must continue on using a certain role which in this context is the super user or admin account. It is also possible to use a standard and normal account but it must execute the command as the admin role. In case of the Ubuntu Linux operating system, it is using the ‘sudo’ command. The following are the step for installing Apache Webserver :

There are two cases on the installing process. The first one is using the ‘root’ account and the latter is using the normal user account.

1. Installing using the ‘root’ account means to perform the installation process as ‘root’ account. In order for a normal user to be a root account, execute the following command to switch from a normal user to a root account :

sudo su -

The following is the execution process of the above command :

user@hostname:~$ sudo su - 
[sudo] password for user: 

2. The second case is using normal user account. If it is not switching to root account and insisting to use the normal user account, just execute the following command using the additional ‘sudo’ command.

3. Type the command for apache2 package installation as follows :

As root account :

apt -y install apache2

As normal user account :

sudo apt -y install apache2

Both of the cu command execution will have the following output :

user@hostname:~$ sudo apt -y install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
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 liblua5.2-0
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,713 kB of archives.
After this operation, 6,920 kB of additional disk space will be used.
Get:1 bionic/main amd64 libapr1 amd64 1.6.3-2 [90.9 kB]
Get:2 bionic/main amd64 libaprutil1 amd64 1.6.1-2 [84.4 kB]
Get:3 bionic/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-2 [10.6 kB]
Get:4 bionic/main amd64 libaprutil1-ldap amd64 1.6.1-2 [8,764 B]
Get:5 bionic/main amd64 liblua5.2-0 amd64 5.2.4-1.1build1 [108 kB]
Get:6 bionic-updates/main amd64 apache2-bin amd64 2.4.29-1ubuntu4.5 [1,071 kB]
Get:7 bionic-updates/main amd64 apache2-utils amd64 2.4.29-1ubuntu4.5 [83.3 kB]
Get:8 bionic-updates/main amd64 apache2-data all 2.4.29-1ubuntu4.5 [160 kB]
Get:9 bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.5 [95.1 kB]
Fetched 1,713 kB in 5s (376 kB/s)  
Selecting previously unselected package libapr1:amd64.
(Reading database ... 147893 files and directories currently installed.)
Preparing to unpack .../0-libapr1_1.6.3-2_amd64.deb ...
Unpacking libapr1:amd64 (1.6.3-2) ...
Selecting previously unselected package libaprutil1:amd64.
Preparing to unpack .../1-libaprutil1_1.6.1-2_amd64.deb ...
Unpacking libaprutil1:amd64 (1.6.1-2) ...
Selecting previously unselected package libaprutil1-dbd-sqlite3:amd64.
Preparing to unpack .../2-libaprutil1-dbd-sqlite3_1.6.1-2_amd64.deb ...
Unpacking libaprutil1-dbd-sqlite3:amd64 (1.6.1-2) ...
Selecting previously unselected package libaprutil1-ldap:amd64.
Preparing to unpack .../3-libaprutil1-ldap_1.6.1-2_amd64.deb ...
Unpacking libaprutil1-ldap:amd64 (1.6.1-2) ...
Selecting previously unselected package liblua5.2-0:amd64.
Preparing to unpack .../4-liblua5.2-0_5.2.4-1.1build1_amd64.deb ...
Unpacking liblua5.2-0:amd64 (5.2.4-1.1build1) ...
Selecting previously unselected package apache2-bin.
Preparing to unpack .../5-apache2-bin_2.4.29-1ubuntu4.5_amd64.deb ...
Unpacking apache2-bin (2.4.29-1ubuntu4.5) ...
Selecting previously unselected package apache2-utils.
Preparing to unpack .../6-apache2-utils_2.4.29-1ubuntu4.5_amd64.deb ...
Unpacking apache2-utils (2.4.29-1ubuntu4.5) ...
Selecting previously unselected package apache2-data.
Preparing to unpack .../7-apache2-data_2.4.29-1ubuntu4.5_all.deb ...
Unpacking apache2-data (2.4.29-1ubuntu4.5) ...
Selecting previously unselected package apache2.
Preparing to unpack .../8-apache2_2.4.29-1ubuntu4.5_amd64.deb ...
Unpacking apache2 (2.4.29-1ubuntu4.5) ...
Setting up libapr1:amd64 (1.6.3-2) ...
Processing triggers for ufw (0.35-5) ...
Processing triggers for ureadahead (0.100.0-20) ...
ureadahead will be reprofiled on next reboot
Setting up apache2-data (2.4.29-1ubuntu4.5) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libaprutil1:amd64 (1.6.1-2) ...
Processing triggers for systemd (237-3ubuntu10.15) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up liblua5.2-0:amd64 (5.2.4-1.1build1) ...
Setting up libaprutil1-ldap:amd64 (1.6.1-2) ...
Setting up libaprutil1-dbd-sqlite3:amd64 (1.6.1-2) ...
Setting up apache2-utils (2.4.29-1ubuntu4.5) ...
Setting up apache2-bin (2.4.29-1ubuntu4.5) ...
Setting up apache2 (2.4.29-1ubuntu4.5) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/ → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/ → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.15) ...
Processing triggers for ufw (0.35-5) ...

Further Installation Process

As in the previous section shows, the installation process is quite simply. Just continue on the installation process as follows :

1. After successfully executing the above command, start the apache service by typing the following command :

systemctl start apache2

The output of the above command execution appears as follows :

user@hostname:~$ sudo systemctl start apache2

2. Don’t forget to check the status of the apache service by typing the following command :

user@hostname:~$ sudo 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
   Active: active (running) since Sat 2019-03-30 13:56:13; 2h 35min ago
  Process: 16174 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 16179 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 16206 (apache2)
    Tasks: 10 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─16206 /usr/sbin/apache2 -k start
           ├─16209 /usr/sbin/apache2 -k start
           ├─16210 /usr/sbin/apache2 -k start
           ├─16211 /usr/sbin/apache2 -k start
           ├─16213 /usr/sbin/apache2 -k start
           ├─16216 /usr/sbin/apache2 -k start
           ├─16280 /usr/sbin/apache2 -k start
           ├─16285 /usr/sbin/apache2 -k start
           ├─16286 /usr/sbin/apache2 -k start
           └─16287 /usr/sbin/apache2 -k start

Mar 30 13:56:13 hostname systemd[1]: Starting The Apache HTTP Server...
Mar 30 13:56:13 hostname apachectl[16179]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress t
Mar 30 13:56:13 hostname systemd[1]: Started The Apache HTTP Server.

3. Don’t forget to set the set the apache service in auto-start mode. It will automatically starts upon every boot or start of the operating system. Just type the following command :

systemctl enable apache2

The output of the above command execution appears as follows :

user@hostname:~$ sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2

4. Last but not least, check it in the browser to request a web page by typing ‘localhost’ in the address bar as shows in the following image :

As the above page appears in the web browser, the apache service finally runs normally to process the request.

Leave a Reply