
Apache is one of the most reliable and widely-used web servers worldwide. It’s open-source, highly configurable, and easy to set up, making it the preferred choice for hosting websites and applications. In this tutorial, We will guide you through Installing Apache on CentOS 8 and Rocky Linux 9 with a step by step.
Table of Contents
- Prerequisites of Installing Apache on CentOS
- Step 1: Update Your System Packages
- Step 2: Install Apache Web Server
- Step 3: Start and Enable Apache
- Step 4: Configure the Firewall
- Step 5: Verify Apache Installation
- Step 6: Manage Apache Service
- Step 7: Configure Apache (Optional)
- Step 8: Enable Apache Modules (Optional)
- Step 9: Secure Apache with SSL (Recommended)
- Conclusion
Prerequisites of Installing Apache on CentOS
Before you begin, make sure you have the following:
- A system running CentOS, Red Hat 8, 9 or Rocky Linux or AlmaLinux 8 or 9.
- Root or sudo access to the server.
- An active internet connection or offline repository configured to install packages.
Step 1: Update Your System Packages
Before installing any software, update your system to ensure you have the latest packages and security updates.
sudo dnf update -y
This command ensures that your system is fully updated and ready for Apache installation.
Step 2: Install Apache Web Server
To install Apache on CentOS 8 or Rocky Linux 9, use the dnf
package manager:
sudo dnf install httpd -y
The -y
flag confirms the installation process without prompting you.
Step 3: Start and Enable Apache
Once installed, start the Apache service and enable it to start at boot:
sudo systemctl start httpd
sudo systemctl enable httpd
To confirm that Apache is running, check its status:
sudo systemctl status httpd
If running, you’ll see output like this:
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Wed 2025-01-22 13:32:24 UTC
Read Also | Best CentOS and Redhat Alternatives | Open Source Linux OS
Step 4: Configure the Firewall
CentOS 8 and Rocky Linux 9 often have firewalld
enabled. You’ll need to allow HTTP and HTTPS traffic for Apache to work properly.
- Check available services in the firewall:
sudo firewall-cmd --list-all
- Allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https
- Reload the firewall:
sudo firewall-cmd --reload
Step 5: Verify Apache Installation
To ensure Apache is working, open a web browser and navigate to your server’s IP address:
http://your-server-ip
You should see the default Apache welcome page, confirming the installation was successful.
To find your server’s IP address, run:
ip a
Step 6: Manage Apache Service
Here are some useful commands for managing the Apache service:
- Restart Apache:
sudo systemctl restart httpd
- Stop Apache:
sudo systemctl stop httpd
- Check Apache Status:
sudo systemctl status httpd
Step 7: Configure Apache (Optional)
Apache configuration files are stored in the /etc/httpd/
directory. The main configuration file is:
/etc/httpd/conf/httpd.conf
Use a text editor like Nano to make changes:
sudo nano /etc/httpd/conf/httpd.conf
After making changes, restart Apache to apply them:
sudo systemctl restart httpd
Step 8: Enable Apache Modules (Optional)
You can enable additional Apache modules to extend its functionality. For example, to enable the rewrite module:
sudo dnf install mod_rewrite
sudo systemctl restart httpd
Read Also | EX200 RHCSA Exam Questions with Solutions: Your Path to RHEL 9 Certification
Step 9: Secure Apache with SSL (Recommended)
Securing your web server with SSL encrypts communication between your server and users. You can use Let’s Encrypt for free SSL certificates.
- Install Certbot:
sudo dnf install certbot python3-certbot-apache -y
- Obtain and configure an SSL certificate:
sudo certbot --apache
- Test SSL auto-renewal:
sudo certbot renew --dry-run
Conclusion
In this guide, we walked you through the process of Installing Apache on CentOS, Red Hat 8 or 9 and Rocky Linux, Alama Linux 8 or 9 step by step. From updating system packages to securing your server with SSL, you now have a fully functional Apache web server ready to host websites and applications. Properly managing and configuring Apache ensures optimal performance and security for your server.
Stay tuned to Magnetbyte for more in-depth tutorials and technical insights!
For more tutorials on server setup, website optimization, and technical reviews, explore more on Magnetbyte!
Read Also | How to Manage DNF Software Modules in Linux: A Comprehensive Guide