How to set up Apache HTTP web server (httpd) in Linux.
Table of Contents
- Introduction
- Overview of httpd
- Prerequisites
- Implementation
1. Introduction
In this tutorial, we will configure an httpd webserver on RHEL-based Linux distributions to serve a simple webpage.
2. Overview of httpd
what is httpd?
- Apache HTTP Server (
httpd) is a web server that serves webpages to clients over HTTP/HTTPS.
Key Information
- Purpose = Serve webpages.
- Service or Package name =
httpd - Configuration Files
/etc/httpd/conf/httpd.conf= Main configuration file./var/www/html/index.html= Default webpage.
- Log Files =
/var/log/httpd/ access_log= Records client requests.error_log= Records server errors.
3. Prerequisites
- Linux server (RHEL / AlmaLinux)
- Internet connectivity (for package installation)
4. Implementation
-
check if the httpd package is already installed
rpm -qa | grep httpd
-
Install httpd
dnf install httpd -y
-
Start and Enable the httpd service
systemctl enable --now httpd
-
Explore the configuration file
cat /etc/httpd/conf/httpd.confImportant parameters:
Listen 80= Defines the port Apache listens on.-
DocumentRoot= Defines the directory where website files are stored. -
IncludeOptional conf.d/*.conf= Loads additional configuration files from theconf.ddirectory.
-
Explore the Default Webpage Location
Apache uses the following directory by default:
/var/www/html/The default webpage:
-
Create your first webpage
Open the default webpage:
vi /var/www/html/index.htmlAdd the following HTML content:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Structure of HTML Document</title> <style> body { margin: 0; min-height: 100vh; display: grid; place-content: center; text-align: center; background: #000; color: #fff; font-family: Georgia, serif; } h1 { font-size: 3rem; font-weight: 400; letter-spacing: 1px; margin: 0; } p { color: #aaa; font-size: 1.1rem; margin-top: 1rem; } </style> </head> <body> <!-- Main content of website --> <h1>Welcome to My First Website</h1> <p>Thanks for visiting my website <3</p> </body> </html>
-
Restart the httpd service
systemctl restart httpd
-
Access Your Website
Open your browser and enter:
http://<Public-IP>
You should see your first webpage.
-
Configure the Firewall / Security Group
If you are using AWS EC2, add an inbound security group rule:
Type Protocol Port Source HTTP TCP 80 0.0.0.0/0 For HTTPS later, use TCP port
443.If using an OS firewall such as
firewalld, allow HTTP too:firewall-cmd --permanent --add-service=http firewall-cmd --reload