- Posted on
- • Apache Web Server
Installing Apache on CentOS/RHEL (`yum/dnf`)
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Installing Apache on CentOS/RHEL using Yum/DNF
Apache HTTP Server, commonly known as Apache, is one of the most used web server software in the world. It’s highly reliable, flexible, and customizable, making it a popular choice for hosting websites. If you're running a CentOS or RHEL (Red Hat Enterprise Linux) server, setting up Apache can be straightforward using the package managers yum
(on older versions like CentOS 7) or dnf
(on newer versions like CentOS 8 and RHEL 8 and later). In this blog post, we'll walk you through the steps to install Apache using these package managers, configure it, and ensure it's running on your system.
Prerequisites
- A system running CentOS/RHEL
- Sudo or root privileges
- Internet connectivity
Step 1: Update Your System
Before installing any new package, it's a good practice to update your package repository to ensure you get the latest versions of the software. Run the following command:
sudo yum update # CentOS 7
sudo dnf update # CentOS 8 / RHEL 8 or later
Step 2: Install Apache
To install Apache using yum
or dnf
, simply run:
sudo yum install httpd # CentOS 7
sudo dnf install httpd # CentOS 8 / RHEL 8 or later
This command downloads and installs the Apache web server and all required dependencies.
Step 3: Start Apache Service
Once the installation is complete, you need to start the Apache service. Use the following command:
sudo systemctl start httpd.service
Step 4: Enable Apache at Boot
To make sure that Apache starts automatically at boot, run:
sudo systemctl enable httpd.service
Step 5: Verify Apache Installation
To confirm that Apache has been installed and is running, you can check its status using:
sudo systemctl status httpd.service
Additionally, you can open a web browser and visit http://your_server_ip/
. If Apache is running, you should see the default Apache welcome page.
Step 6: Configure Firewall
If you have firewalld enabled (which is default on many installations), you’ll need to open port 80 (HTTP) and 443 (HTTPS) to allow traffic to your web server. Run the following commands:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 7: Configure Apache
Now that Apache is installed, you can begin configuring it to serve your websites. Apache’s configuration files are located in /etc/httpd/conf/httpd.conf
by default. You can edit this file to change server settings. For more specific configurations like virtual hosts, you might need to look in /etc/httpd/conf.d/
for additional configuration files.
Conclusion
Installing Apache on CentOS or RHEL using yum
or dnf
is a straightforward process that can be completed in a few simple steps: updating your system, installing Apache, ensuring the service runs at boot, opening necessary ports in the firewall, and making initial configuration changes. Apache serves as a robust platform for hosting your applications or websites, offering vast flexibility and strong community support. Whether you are setting up a local test environment or a production server, Apache, in conjunction with CentOS or RHEL, provides a stable and scalable environment to meet your needs. Make sure to secure and optimize Apache based on the specific requirements of your project for best results.
Further Reading
Here are some further reading suggestions related to installing and configuring Apache on CentOS/RHEL:
Understanding Apache Configuration: Learn more about how Apache can be configured for optimal performance and security. Apache Configuration Guide
Apache Virtual Hosts: Detailed guide on setting up Apache virtual hosts, allowing you to host multiple websites on a single server. Apache Virtual Hosts Guide
Securing Apache: Best practices for securing your Apache web server, including tips on SSL/TLS and HTTP headers. Apache Security Tips
Troubleshooting Common Apache Issues: Helpful guide for diagnosing and solving common issues that may arise with Apache installations. Apache Troubleshooting
Optimizing Apache Performance: Techniques to enhance the performance of your Apache server, such as caching, load balancing, and tuning parameters. Optimize Apache Performance
These resources will provide comprehensive information to deepen your understanding of managing and optimizing Apache installations on CentOS/RHEL platforms.