Step-by-Step Guide: Configuring Firewalld for Apache Web Server on Red Hat Linux

Securing your Apache web server with Firewalld is essential for managing incoming and outgoing traffic. If http and https services are absent, don’t worry; I will show you how to add them. Here’s the complete guide: Step 1: Install Apache Web Server Ensure that Apache is installed and running: Update your system: sudo yum update Install Apache: sudo yum install httpd Start and enable Apache: sudo systemctl start httpd sudo systemctl enable httpd Step 2: Verify Firewalld Installation Check if Firewalld is installed and running: sudo systemctl status firewalld If it’s not running, start and enable it: sudo systemctl start firewalld sudo systemctl enable firewalld Step 3: Check and Add HTTP/HTTPS Services To ensure that your Apache server can communicate properly, HTTP and HTTPS services need to be enabled. Here’s how: List Available Services Check if http and https services are available: sudo firewall-cmd --get-services If they are listed, proceed to add them in the next step. Manually Add Missing Services If http or https is missing, create a custom service file: Navigate to the services directory: cd /etc/firewalld/services/ Create a new XML file (e.g., http.xml) for HTTP: sudo nano http.xml Add the following content: HTTP Web server HTTP service Repeat the steps for https.xml, using port 443. Reload Firewalld to register the services: sudo firewall-cmd --reload Enable HTTP/HTTPS Add the services permanently to Firewalld: sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https Reload to apply changes: sudo firewall-cmd --reload Step 4: Verify Firewall Rules After adding the services, verify they are active: sudo firewall-cmd --list-all You should see http and https listed under the services. Step 5: Test Apache Access Confirm your setup by accessing your Apache server: Open a web browser and visit: HTTP: http://your_server_ip HTTPS: https://your_server_ip You should see the Apache default page. By following these steps, you’ve ensured that your Apache server is configured securely with Firewalld—even if http and https were missing initially. This setup protects your web server and allows seamless communication.

Apr 16, 2025 - 23:44
 0
Step-by-Step Guide: Configuring Firewalld for Apache Web Server on Red Hat Linux

Securing your Apache web server with Firewalld is essential for managing incoming and outgoing traffic. If http and https services are absent, don’t worry; I will show you how to add them. Here’s the complete guide:

Step 1: Install Apache Web Server

Ensure that Apache is installed and running:

  1. Update your system:
   sudo yum update
  1. Install Apache:
   sudo yum install httpd
  1. Start and enable Apache:
   sudo systemctl start httpd
   sudo systemctl enable httpd

Step 2: Verify Firewalld Installation

Check if Firewalld is installed and running:

sudo systemctl status firewalld

If it’s not running, start and enable it:

sudo systemctl start firewalld
sudo systemctl enable firewalld

Step 3: Check and Add HTTP/HTTPS Services

To ensure that your Apache server can communicate properly, HTTP and HTTPS services need to be enabled. Here’s how:

  1. List Available Services Check if http and https services are available:
   sudo firewall-cmd --get-services

If they are listed, proceed to add them in the next step.

  1. Manually Add Missing Services

    If http or https is missing, create a custom service file:

    • Navigate to the services directory:
     cd /etc/firewalld/services/
    
  • Create a new XML file (e.g., http.xml) for HTTP:

     sudo nano http.xml
    

    Add the following content:

     
     
       HTTP
       Web server HTTP service
        protocol="tcp" port="80"/>
     
    

    Repeat the steps for https.xml, using port 443.

  • Reload Firewalld to register the services:

     sudo firewall-cmd --reload
    
  1. Enable HTTP/HTTPS Add the services permanently to Firewalld:
   sudo firewall-cmd --permanent --add-service=http
   sudo firewall-cmd --permanent --add-service=https

Reload to apply changes:

   sudo firewall-cmd --reload

Step 4: Verify Firewall Rules

After adding the services, verify they are active:

sudo firewall-cmd --list-all

You should see http and https listed under the services.

Step 5: Test Apache Access

Confirm your setup by accessing your Apache server:

  1. Open a web browser and visit:
    • HTTP: http://your_server_ip
    • HTTPS: https://your_server_ip
  2. You should see the Apache default page.

By following these steps, you’ve ensured that your Apache server is configured securely with Firewalld—even if http and https were missing initially. This setup protects your web server and allows seamless communication.