How to Install and Configure Apache HTTP Server in Rocky Linux 8/9 – Part 1

Introduction

The Apache HTTP Server is a popular web server used to host websites on Linux.
It serves web pages to clients using the HTTP protocol. Understanding Apache is essential for Linux administrators and web hosting setups.

How Web Servers Work

  • Web servers listen on port 80 (HTTP) or 443 (HTTPS).
  • They receive requests from clients (browsers) and respond with HTML, CSS, JavaScript, or other content.
  • Apache can host multiple websites using virtual hosting.

Server Information


Package Name: httpd
Configuration File: /etc/httpd/conf/httpd.conf
Service Name: httpd
Ports: 80 (HTTP), 443 (HTTPS)
Server IP: Example - 192.168.1.100

Step 1: Install Apache HTTP Server


dnf install httpd -y

Step 2: Start and Enable Apache Service


systemctl start httpd
systemctl enable httpd
systemctl status httpd

Step 3: Configure Firewall


firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Step 4: Verify Web Server

Open a browser and visit http://your-server-ip. You should see the Apache default page.

Step 5: Set up Virtual Hosting

We will create two virtual hosts: www.bitscentric.local and www.galaxy.local.

# Create directories for websites
mkdir -p /var/www/bitscentric.local/public_html
mkdir -p /var/www/galaxy.local/public_html

# Create index.html for both sites
echo "<h1>Welcome to Bitscentric</h1>" > /var/www/bitscentric.local/public_html/index.html
echo "<h1>Welcome to Galaxy</h1>" > /var/www/galaxy.local/public_html/index.html

Step 6: Configure Virtual Host Files


# Bitscentric virtual host
vi /etc/httpd/conf.d/bitscentric.local.conf
# Add:
<VirtualHost *:80>
    ServerName www.bitscentric.local
    DocumentRoot /var/www/bitscentric.local/public_html
    ErrorLog /var/www/bitscentric.local/error.log
    CustomLog /var/www/bitscentric.local/requests.log combined
</VirtualHost>

# Galaxy virtual host
vi /etc/httpd/conf.d/galaxy.local.conf
# Add:
<VirtualHost *:80>
    ServerName www.galaxy.local
    DocumentRoot /var/www/galaxy.local/public_html
    ErrorLog /var/www/galaxy.local/error.log
    CustomLog /var/www/galaxy.local/requests.log combined
</VirtualHost>

Step 7: Restart & Enable Apache Service


systemctl restart httpd

systemctl enable httpd

Step 8: Test Virtual Hosts

Add the server IPs and domains to your client /etc/hosts file for testing:


192.168.1.100 www.bitscentric.local
192.168.1.100 www.galaxy.local

Open a browser and check both domains to verify the setup.

Additional Tips

  • Keep DocumentRoot directories organized per site.
  • Enable SSL using mod_ssl for secure HTTPS connections.
  • Monitor logs: /var/log/httpd/ for troubleshooting.
  • Use .htaccess for directory-level configuration and security.

Conclusion

Apache HTTP Server is a powerful tool to host websites on Linux.
With virtual hosting, you can host multiple domains on a single server.
Proper configuration, firewall setup, and monitoring are essential for a production-ready web server.

Leave a Reply

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