install http apache web server
install http apache web server

How To Set up HTTP Server On CentOS Stream 9

For some people, a web server is a tool and asset that can be used to improve the quality of their business. By using the correct web server, we can make our business widely known to the general public, thereby increasing revenue. In this short article we will learn how to set up HTTP Apache Web Server (httpd) on CentOS Stream 9 operating system.

Introduction

An HTTP (Hypertext Transfer Protocol) server is a fundamental component of web infrastructure, responsible for serving web content to clients across the internet. Whether we’re hosting a personal blog, an e-commerce site, or a large-scale web application, understanding how an HTTP server works and how to set one up is essential. In this article, we’ll delve into the basics of HTTP servers, their role in web communication, and how to set up a basic HTTP server using popular tools like Apache on CentOS.

What is an HTTP Server?

At its core, an HTTP server is a software application that listens for incoming HTTP requests from clients (such as web browsers) and responds with the appropriate content. When you type a website’s URL into your browser and hit Enter, your browser sends an HTTP request to the server hosting that website, and the server responds with the requested web page, images, or other resources.

Components of an HTTP Server

HTTP Server has many important components as shown below :

  1. Listener: An HTTP server listens for incoming requests on a specific port, commonly port 80 for HTTP and port 443 for HTTPS (secure HTTP).
  2. Request Handler: Upon receiving a request, the server processes it and determines how to respond based on factors like the requested URL, headers, and parameters.
  3. Content Provider: The server retrieves or generates the requested content (HTML files, images, scripts, etc.) and sends it back to the client in the HTTP response.

How to Set Up an HTTP Server on CentOS Stream 9

For setting up an HTTP server on CentOS, we’ll use Apache HTTP Server, one of the most widely used web servers globally. There are several steps in setting up HTTP Serve on CentOS Stream 9 as listed below :

  1. Prerequisites
  2. Installing HTTP Apache Web Server
  3. Test the HTTP Apache Web Server Installation

Prerequisites

Before getting started to install HTTP Server on CentOS Stream 9, we will list the prerequisites which is to be fulfilled, as show below :

  1. server running CentOS Stream 9
  2. root account or sudo privileges that we can install packages and make changes to the system.
  3. basic understanding of Linux commands and how to use a text editor such as nano or vi.

Installing HTTP Apache Web Server

At this stage, we will install HTTP Apache web server on CentOS Stream 9 with following commands line

1. Update System Package

It’s advised to update our package repository to ensure we’re getting the latest version of HTTPS web server by submitting command line :

$ sudo dnf update -y

2. Install HTTP Apache Web Server

To install Apache Web Server on CentOS Stream 9, we will use following command line :

$ sudo dnf install httpd -y

Output :

[ramansah@bckinfo ~]$ sudo dnf install httpd -y
Last metadata expiration check: 5:52:12 ago on Fri 03 May 2024 04:24:35 PM WIB.
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
httpd x86_64 2.4.57-8.el9 appstream 48 k
Installing dependencies:
centos-logos-httpd noarch 90.4-1.el9 appstream 252 k
Installing weak dependencies:
mod_http2 x86_64 2.0.26-1.el9 appstream 163 k
mod_lua x86_64 2.4.57-8.el9 appstream 60 k

Transaction Summary
============================================================================================================
Install 4 Packages

Total download size: 523 k
Installed size: 1.1 M
Downloading Packages:
(1/4): httpd-2.4.57-8.el9.x86_64.rpm 254 kB/s | 48 kB 00:00
(2/4): centos-logos-httpd-90.4-1.el9.noarch.rpm 1.2 MB/s | 252 kB 00:00
(3/4): mod_lua-2.4.57-8.el9.x86_64.rpm 1.4 MB/s | 60 kB 00:00
(4/4): mod_http2-2.0.26-1.el9.x86_64.rpm 658 kB/s | 163 kB 00:00
------------------------------------------------------------------------------------------------------------
Total 630 kB/s | 523 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mod_lua-2.4.57-8.el9.x86_64 1/4
Installing : centos-logos-httpd-90.4-1.el9.noarch 2/4
Installing : mod_http2-2.0.26-1.el9.x86_64 3/4
Installing : httpd-2.4.57-8.el9.x86_64 4/4
Running scriptlet: httpd-2.4.57-8.el9.x86_64 4/4
Verifying : centos-logos-httpd-90.4-1.el9.noarch 1/4
Verifying : httpd-2.4.57-8.el9.x86_64 2/4
Verifying : mod_http2-2.0.26-1.el9.x86_64 3/4
Verifying : mod_lua-2.4.57-8.el9.x86_64 4/4

Installed:
centos-logos-httpd-90.4-1.el9.noarch httpd-2.4.57-8.el9.x86_64 mod_http2-2.0.26-1.el9.x86_64
mod_lua-2.4.57-8.el9.x86_64

3. Starting Up HTTP Web Server Service

After installing HTTP web server is completed done, we will start its service and enable it to ensure if the service will be started automatically when the system is booted. We will submit following command lines :

$ sudo systemctl start httpd
$ sudo systemctl status httpd
$ sudo systemctl enable httpd

Output :

[ramansah@bckinfo ~]$ sudo systemctl start httpd
[ramansah@bckinfo ~]$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
Drop-In: /etc/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Fri 2024-05-03 22:18:42 WIB; 2s ago
Docs: man:httpd.service(8)
Main PID: 6518 (httpd)
Status: "Started, listening on: port 80"
Tasks: 177 (limit: 22831)
Memory: 32.4M
CPU: 94ms
CGroup: /system.slice/httpd.service
├─6518 /usr/sbin/httpd -DFOREGROUND
├─6519 /usr/sbin/httpd -DFOREGROUND
├─6520 /usr/sbin/httpd -DFOREGROUND
├─6521 /usr/sbin/httpd -DFOREGROUND
└─6522 /usr/sbin/httpd -DFOREGROUND

May 03 22:18:41 bckinfo systemd[1]: Starting The Apache HTTP Server...
May 03 22:18:42 bckinfo httpd[6518]: AH00558: httpd: Could not reliably determine the server's fully qualif>
May 03 22:18:42 bckinfo systemd[1]: Started The Apache HTTP Server.
May 03 22:18:42 bckinfo httpd[6518]: Server configured, listening on: port 80
[ramansah@bckinfo ~]$ sudo systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Starting up HTTP Web Server on CentOS Stream 9

Testing HTTP Apache Web Server Installation

In this stage, we will configure and test HTTP Apache Web Server installation by creating a simple page and query it from web browser.

  1. Rename or remove welcome page
  2. Configure httpd.
  3. If Firewalld is running, allow HTTP service.
  4. Create a HTML test page.

1. Rename or remove welcome page

$ sudo mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org

2. Configure httpd.

At this step, we will Replace server name to our own environment. The httpd configuration file is locate at /etc/httpd/conf/httpd.conf file.

[ramansah@bckinfo ~]$ sudo vi /etc/httpd/conf/httpd.conf 


# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
#ServerAdmin root@localhost
ServerAdmin root@bckinfo

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName http://bckinfo.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.

3. If Firewalld is running, allow HTTP service

At this stage we will allow https service if firewalld service is running.

[ramansah@bckinfo ~]$ sudo firewall-cmd --add-service=http 
success
[ramansah@bckinfo ~]$ sudo firewall-cmd --runtime-to-permanent
success

4. Create a HTML test page

At this stage we will create a HTML test page and access to it from any client.

$ sudo vi /var/www/html/index.html
[ramansah@bckinfo ~]$ sudo vi /var/www/html/index.html 

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Testing Page
</div>
<div style="width: 100%; font-size:20px; font-weight: bold; text-align: center;">
Installing Apache httpd on CentOS Stream 9 - bckinfo.com
</div>
</body>
</html>

~
"index.html" 12L, 280B

Then we will access it from the browser as shown below :

HTTP Apache Web server testing page

Until this final step, we have installed HTTP Apache web server on CentOS Stream 9 operating system successfully.

Conclusion

Setting up an HTTP server is an essential skill for anyone involved in web development or website hosting. With tools like Apache HTTP Server and Nginx, we can quickly deploy a robust web server to serve our web content reliably and efficiently. Understanding the basics of HTTP communication and server configuration empowers us to manage and optimize your web infrastructure effectively.

(Visited 165 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *