How to Install Apache on AlmaLinux 9
Install the Apache HTTP Server on AlmaLinux 9 using the package manager. Configure basic settings and verify the service is running correctly.
You will install the Apache HTTP Server on a fresh AlmaLinux 9 system. These steps target AlmaLinux 9 with the default repositories enabled and require root privileges or sudo access.
Prerequisites
- AlmaLinux 9 installed and updated.
- Root access or a user account with
sudoprivileges. - Internet connection to download packages.
- At least 512 MB of free RAM (recommended 1 GB+ for production).
Step 1: Update the system
Before installing new software, ensure your package lists are current. This prevents conflicts between old and new versions of libraries.
sudo dnf update -y
Wait for the process to complete. You will see a summary of packages downloaded and installed. The output ends with Complete!.
Step 2: Install Apache
Install the Apache HTTP Server package using the dnf package manager. The -y flag automatically answers "yes" to prompts.
sudo dnf install httpd -y
The installation downloads the Apache binary and related dependencies. Watch the progress bar and read the package names being installed. Once finished, the output confirms the installation was successful.
Step 3: Start the Apache service
Start the Apache service immediately after installation. This launches the web server and begins listening for incoming connections.
sudo systemctl start httpd
The command returns to the prompt without error if the service starts successfully.
Step 4: Enable Apache on boot
Configure Apache to start automatically when the system boots. This ensures the web server is always available after a reboot.
sudo systemctl enable httpd
This creates a symbolic link in the systemd directory to trigger the service at boot time.
Step 5: Configure the firewall
Allow incoming traffic on port 80 (HTTP) and port 443 (HTTPS) through the firewall. Without this, external users cannot reach your site.
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=https --permanent
Reload the firewall rules to apply the changes immediately.
sudo firewall-cmd --reload
Verify the installation
Check the status of the Apache service to confirm it is active and running.
sudo systemctl status httpd
You should see active (running) in the status line. The output will list the main process ID (PID) and the number of jobs controlled.
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-01-15 10:00:00 UTC; 5min ago
Open a web browser and navigate to http://your-server-ip. You should see the default Apache test page with the text It works! displayed.
Troubleshooting
If you encounter issues, review the following common errors and their fixes.
Error: "Failed to start The Apache HTTP Server"
Check the error log for specific details.
sudo tail -n 50 /var/log/httpd/error_log
Common causes include missing SSL certificates or permission issues. Fix file permissions with sudo chown -R apache:apache /var/www/html.
Error: "Port 80 is already in use"
Another process is blocking port 80. Check what is listening.
sudo netstat -tulpn | grep :80
Kill the conflicting process or change the port in your configuration.
Error: "Permission denied: /var/www/html"
The Apache user cannot read the document root. Fix ownership.
sudo chown -R apache:apache /var/www/html
Ensure the directory permissions are set to 755.
Error: "Firewall blocked connection"
The firewall rules were not applied correctly. Reload the firewall again.
sudo firewall-cmd --reload
Verify the port is open using sudo firewall-cmd --list-ports.