Install & Configure Apache Web Server In Linux – httpd

Learn how to install and configure Apache web server in Linux. Understand the httpd configuration file and how to start, stop & enable Apache (httpd) in Linux.


What Is Apache

Apache, also called Apache http server is an open-source web server. A web server, of course, is responsible for handling web requests from various computers hitting the web. (No web server, no website).

Just as there is an Apache web server, there are also a lot of web servers out there such as Nginx, IIS, Tomcat, etc.

Tomcat is also called Apache tomcat because it is developed by the same company that developed Apache (Apache Software Foundation)

Apache is a very popular and commonly used web server and can run on both Linux and Windows operating systems.

Just as Nginx, Apache can handle hundreds of thousands of connections trying to fetch information from the web concurrently.

With Apache, you can customize your configuration by using the “.htaccess” file.

When it comes to the Content Management System (CMS) such as WordPress, Joomla, and Drupal, they all work perfectly well on Apache, even without less or no configuration, hence why most web hosting companies use Apache and now Nginx as their web servers.

Apache application/daemon for Linux is “httpd”

How Do I Start Apache (httpd) On Linux

The same way you start other services on Linux is also the same way Apache is started.

To start Apache, use the command

# systemctl start httpd

To Stop Apache, use the command,

# systemctl stop httpd

To enable Apache, use the command,

# systemctl enable httpd

Apache (httpd) Configuration file

core apache configuration file is in the path /etc/httpd/conf/httpd.conf)

Let’s see the contents in this file.

[root@HQDEV1 ~]# cat /etc/httpd/conf/httpd.conf

search for the line “DocumentRoot”

Apache web server in Linux

you can see the httpd document root (/var/www/html). It is one of the important parameters in the httpd configuration file.

Every website file will have to be on this path. The document root can be changed, especially for hardening web server security.

We will look at how to successfully change the document root of httpd when we get to the advanced configuration in another lesson.

httpd by default listens on port 80.

What is LAMP stack

If you know LEMP stack, you will also know LAMP stack.

LAMP stack consists of (Linux, Apache, MySQL, and PHP). They are all web development software used to manage web applications.

How to install LAMP stack in Linux (RHEL 8 / CentOS 8)

To install Linux (RHEL 8) click here.

And Of course, in the “ACTION TIME” of this lesson, we will install Apache & configure a basic website.

To install MySQL, click on this link

To install PHP, click on this link.

Having understood what Apache is, let’s get to installing and configuring Apache for a basic website.


How To Install & Configure Apache httpd On Linux (RHEL / CentOS 7 & 8)

we will look at how to configure Apache for a basic website.

1. Install Apache web server

[root@HQDEV1 ~]# yum install httpd

Updating Subscription Management repositories.
Last metadata expiration check: 0:36:27 ago on Sat 04 Jul 2020 10:17:20 PM WAT.



2. create a web file in the document root location.

[root@HQDEV1 ~]# vi /var/www/html/tekneed
This is a test website

3. Start the httpd service

[root@HQDEV1 ~]# systemctl start httpd

4. If you wish, you can enable the httpd service

[root@HQDEV1 ~]# systemctl enable httpd

Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/httpd.service.

5. Verify the service has started

[root@HQDEV1 ~]# systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-07-04 23:08:53 WAT; 10min ago
     Docs: man:httpd.service(8)
 Main PID: 45702 (httpd)
   Status: "Running, listening on: port 80"

6. Test your configuration

You can use any browser or use a text-based browser such as elinks.

To use elinks in RHEL 7, install elinks by using the command,

[root@HQDEV1 ~]# yum install elinks

To install elinks in RHEL 8 or CentOS 8, click on this link

7. Now that elinks has been installed, do a test.

[root@HQDEV1 ~]# elinks http://localhost/tekneed

press the enter key to open the file

This is a test website

You can see that the web server is properly configured.

In another tutorial, we will look at the advanced configuration of the Apache web server

Your feedback is welcomed. If you love others, you will share with others


Leave a Reply

Your email address will not be published.