
Apache is one of the most widely used open-source web servers, offering robust performance and flexibility for hosting websites and applications. In this guide, we will walk you through the steps to install and configure Apache on Rocky Linux 9.
Prerequisites
Before starting, ensure the following:
- You have a Rocky Linux 9 server with root or sudo privileges.
- Your server is connected to the internet.
Step 1: Update Your System
Before installing any software, it is good practice to update the package repository to ensure you’re installing the latest available versions. Run the following command:
sudo dnf update -y
Step 2: Install Apache
Apache is available in the default Rocky Linux repositories. To install it, use the following command:
sudo dnf install httpd -y
This command downloads and installs the Apache web server along with its dependencies.
Step 3: Start and Enable Apache
After installation, you need to start the Apache service and enable it to start automatically at boot:
sudo systemctl start httpd
sudo systemctl enable httpd
You can verify the status of Apache using:
sudo systemctl status httpd
If everything is working correctly, you should see a status message indicating that Apache is active and running.
Step 4: Adjust the Firewall
If your server has a firewall enabled, you need to allow HTTP and HTTPS traffic. Run the following commands to allow Apache through the firewall:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 5: Verify Apache Installation
To confirm that Apache is installed and running, open your web browser and navigate to your server’s IP address:
http://your-server-ip
You should see the default Apache welcome page, indicating that the web server is working properly.
Step 6: Configure Apache (Optional)
Apache’s configuration files are located in the /etc/httpd/
directory. Some key files and directories include:
/etc/httpd/conf/httpd.conf
: The main Apache configuration file./etc/httpd/conf.d/
: Directory for additional configuration files./var/www/html/
: Default document root for serving web pages.
You can edit these files to customize your Apache setup. For example, to change the default document root, edit the httpd.conf
file and update the DocumentRoot
directive.
After making any changes, restart Apache to apply them:
sudo systemctl restart httpd
Conclusion
You have successfully installed Apache on Rocky Linux 9! From here, you can start hosting websites or applications. Apache’s flexibility and extensive documentation make it an excellent choice for a wide range of use cases. Remember to regularly update your server and monitor its performance to ensure smooth operation.