Setting up an Apache Web Server on Linux

There are many web servers you can configure in Linux. Most servers run using a Linux OS because of the stability, the level of security and the capacity of the Operating System to run multiple processes and a pool of tasks at the same time. Since a greater utility of the Linux OS is at the command line, it makes it easier to run both onsite and remotely coupled with the fact that Linux the cost of maintaining a Linux server is low since it's open source.

Web servers are used to serve web pages on the internet by rendering the HTML files housed in a computer each time there is a request by client computers. Websites and web applications are hosted on web servers and are accessed via HTTP/HTTPS.

A web server is a type of server software like database servers, mail servers, etc which accesses HTML files stored on another server which could be an operating system to display its content on a web page to be accessible via HTTP request from client computers.

Different web servers are serving majorly the same purpose and a few of them are customized to serve a more distinctive purpose aside from the other.

Prominent web servers are Apache, Nginx, Apache tomcat, Litespeed, Lighttpd, Internet Information Services, etc.

Walk through setting up apache2 on Linux.

Apache2.0, an upgraded apache generally referred to as apache2. Apache is one of the most popular web servers. Running on an HTTP server initiates a connection between a server which could be an operating system and the browsers of website visitors.

How it works - when a user wants to visit a website. The requested page (Homepage, Contact, About, services, etc) is made available via a request that is sent via the visitor's web browser to the website's host server. Apache is the "errand" software that takes this request to return the desired response to the visitor's web browser.

Through the HTTP protocol, Apache serves as a medium for smooth, easy and secure communication between the client (visitors browser) and the server (which be a physical computer or cloud infrastructure).

Apache has quite some features which are not limited to virtual hosting, a functionality that allows a single apache server to serve across a variety of websites, multiprotocol, and can run in a hybrid multi-process mode (MPM), a module which adds more functions to its software. Apache is flexible and easy to use. There is no licence required to run apache since it is open-source. Strong support for non UNIX like systems.

However, apache is best suited for handling websites with less traffic. There could be an issue of performance once there is a spike in traffic coming into the website. Secondly, its many configurations are an issue of serious security concerns.

Apache installation in some Linux distros.

If you are not logged in as a superuser, you can copy the command the way it is, if you are logged in as a superuser, you don't need sudo.

**For Debian and Ubuntu, **

$ sudo apt update $ sudo apt install apache2 -y

For Red Hat and Fedora,

$ sudo dnf update $ sudo install httpd -y

For CentOS,

$ sudo yum update $ sudo yum install httpd -y

Note: for any demonstration in the article, we are using a Debian-based operating system. The commands are the same for Ubuntu. But, for commands where I used apache2, kindly replace it with httpd if you are using Red Hat, Fedora or CentOS.

To check if apache is successfully installed.

$ apache2 -v

version_1.png

Your shell will display the version of the software you have rightly installed.

To start using Apache in Debian,

$ systemctl start Apache2

or

$ service apache2 start

This would prompt you to authenticate with your password.

start_1.png

Check to be sure Apache is actually running

$ systemctl status apache2

or

$ service apache2 start

enable_1.png

Apache comes with a default web page which can be viewed through your web browser. Navigate to your browser and type the loopback address. If you run $ ifconfig on your terminal, the output will show your loopback address. The loopback address is also called the local host, an internal address that routes within a system. However, the loopback address is the same with all devices as 127.0.0.1

With http://127.0.0.1, you have your website displayed on your browser. How nice! The default web page displayed on the browser is to show that apache is working. Now, we head over to the terminal to configure it to serve us.

The /var/www/html directory manages all the websites and the contents to be hosted on the server. Step into the directory with

$ cd /var/www/html Use a text editor of your choice to edit the HTML file, it could be nano, vim (vi), gedit, etc

$ nano index.html

If prompted with any permission error, you can add the $ sudo command to edit the file as root.

You can type in anything you want within the text editor, it could be a copy of HTML code, or just plain texts. Save it with control x, hit the y key and hit enter.

Use the loopback address once again on your browser and view the changes.

Recall we used systemctl start apache2 to get our website running. Once we turn off our system, the website will shut down. To keep the website up and running,

$ systemctl enable apache2

check if this worked using

$ systemctl is-enabled apache2

Also to disable Apache2 from starting on boot,

$ Systemctl disable Apache2

$ service apache2 disable