Install Apache Server in Ubuntu 20.04 Operating System Cloud Hosting

In cloud hosting, once ubuntu server 20.04 is installed successfully, then to upload a web application (website) we need a server software package. Currently Apache and Nginx are two popular server software packages. If you are confused which one to use, I would recommend to install Apache because there are flood of tutorials available for apache, plenty discussion forums too exist.

To install apache in your cloud hosted ubuntu 20.04 operating system, first login with non root user account which has super user privileges. (If you have no idea, what I have just mentioned then follow the second tutorial in the cloud hosting tutorial series. You can find the all the chapter tutorials below this article)

Install Apache

First job is to update ubuntu softwares. Following command is going to do this job.

test@tester:~$ sudo apt update

It will take couple of minutes and all the required updates will be installed.

Its time to install the apache software package. The current version of apache is apache2. It means you are required to install apache2 using following command.

test@tester:~$ sudo apt install apache2

It will take couple of minutes. If it asks for permission with yes or no option, then type ‘y’ and press enter. (Basically these permissions will be to use memory space for software installation)

Then the system is loaded with apache2 server.

Here we have a problem. And that is, if you have followed all the chapters from this series, then in one of the previous chapter we have enabled firewall for openssh only. It means to allow network traffic to and from apache2 server we must have to turn on the firewall for the apache 2 server.

Read: Firewall setup for OpenSSH

Turn on firewall for Apache

Following command is going to enable firewall rule for Apache

test@tester:~$ sudo ufw allow in “Apache Full”

Because we have added a new rule to the firewall configuration protocol ufw, its time to enable it again. Following command will enable the ufw.

test@tester:~$ sudo ufw enable

A warning message may appear: Command may disrupt existing ssh connections

press y and enter

In next couple of minutes, firewall will be on for apache.

Upon success, it will print:Firewall is active and enabled on system startup

For confirmation, use following command.

test@tester:~$ sudo ufw status

Status: active

To                                Action                               From
—                                   —–                                    —-
OpenSSH                ALLOW                          Anywhere
Apache                  Full ALLOW                     Anywhere
OpenSSH (v6)         ALLOW                       Anywhere (v6)
Apache Full (v6)      ALLOW                    Anywhere (v6)

If you see similar message, then ufw is successfully set for openssh and apache.

Test Apache Server Running

So far we have installed apache server in Ubuntu Operating system and set firewall for apache. Now its time to check whether the apache software is successfully running or not.

Following command will help to find out the running status of Apache2 server

test@tester:~$ sudo service apache2 status

(Remember whenever you use apache in a command, then always use apache2 instead of apache)

● 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 Sat 2020-08-10 08:44:04 IST;
Main PID: 5727 (apache2)
Tasks: 55 (limit: 4915)
CGroup: /system.slice/apache2.service
├─5727 /usr/sbin/apache2 -k start
├─5728 /usr/sbin/apache2 -k start
└─5729 /usr/sbin/apache2 -k start

Aug 10 08:44:04 ubuntu2004 systemd[1]: Starting The Apache HTTP Server…
Aug 10 08:44:04 ubuntu2004 apachectl[5675]: AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1.
Aug 10 08:44:04 ubuntu2004 systemd[1]: Started The Apache HTTP Server.

If you see similar above output then it means, it is running. Focus on the active status in the above output. It is showing active and in the bracket(active).

For any reason, if you find active status as failed after running the above mentioned command, then it means the apache server is not properly installed, it has errors.

Now lets see if web application can be uploaded or created in this apache server.

Open a web browser and type your cloud hosting ip address. If you see below default webpage then the apache server is acting appropriately.

Apache Server installation

Conclusion

I hope this article helps to install apache2 server package in ubuntu operating system 20.04 hosted in a cloud hosting like Digital Ocean or Amazon AWS. The above guide is also suitable to install apache in virtual private server.