AlmaLinuxRHEL Based

How To Install Apache on AlmaLinux 10

Install Apache on AlmaLinux 10

Apache HTTP Server remains one of the world’s most trusted and widely-used web servers, powering millions of websites across the globe. When paired with AlmaLinux 10, a robust RHEL-based distribution, it creates an enterprise-grade hosting environment that’s both reliable and cost-effective. This comprehensive guide will walk you through the complete process of installing, configuring, and securing Apache on AlmaLinux 10.

Whether you’re a system administrator setting up your first web server or an experienced developer deploying production applications, this tutorial provides everything you need to get Apache running smoothly on your AlmaLinux system. You’ll learn not just the basic installation steps, but also essential configuration practices, security hardening techniques, and troubleshooting methods that will serve you well in real-world scenarios.

Prerequisites and System Requirements

Before diving into the Apache installation process, ensure your AlmaLinux 10 system meets the necessary requirements and you have the proper access permissions.

System Requirements

Your AlmaLinux 10 server should have a minimum of 1GB RAM, though 2GB or more is recommended for production environments. Ensure you have at least 5GB of free disk space to accommodate Apache, its dependencies, and future log files. A stable network connection is essential for downloading packages and updates during the installation process.

You’ll need either root access or a user account with sudo privileges to execute the installation commands. Basic familiarity with Linux command-line operations will help you follow along more easily, though we’ll explain each step in detail.

Pre-installation Checklist

Verify your AlmaLinux 10 installation is complete and functioning properly by checking the system version with cat /etc/almalinux-release. Confirm your network configuration allows outbound connections to package repositories. Check available disk space using df -h to ensure sufficient storage for the installation.

Basic security considerations include reviewing existing firewall rules and understanding your server’s current network exposure. If this server will be publicly accessible, plan your security strategy before proceeding with the installation.

System Preparation and Updates

Proper system preparation forms the foundation of a successful Apache installation. Starting with a fully updated system reduces potential conflicts and ensures access to the latest security patches.

Updating the System

Always begin by updating your AlmaLinux 10 system to the latest available packages. This critical step prevents compatibility issues and ensures your server has the most recent security updates.

sudo dnf check-update
sudo dnf update

The dnf check-update command shows available updates without installing them, while dnf update performs the actual upgrade process. If kernel updates are included, reboot your system to ensure the new kernel loads properly:

sudo reboot

Monitor the update process carefully. Large updates may take several minutes depending on your internet connection speed and the number of packages requiring updates.

Package Manager Configuration

AlmaLinux 10 uses the DNF (Dandified YUM) package manager, which provides improved performance and dependency resolution compared to older package managers. Understanding DNF’s basic operations will help you manage Apache and related packages effectively.

Verify your repository configuration is working correctly by running dnf repolist. This command displays all enabled repositories and their status. If you encounter repository issues, clean the DNF cache with sudo dnf clean all before retrying operations.

Consider enabling additional repositories if your setup requires specific modules or tools not available in the default AlmaLinux repositories. However, be cautious about third-party repositories to maintain system stability and security.

Apache Installation Process

With your system properly prepared, you can now proceed with installing Apache HTTP Server on AlmaLinux 10. The installation process is straightforward but requires attention to detail for optimal results.

Installing Apache Packages

Install Apache using DNF with the following command, which downloads and installs the Apache HTTP Server package along with essential tools:

sudo dnf install httpd httpd-tools

The httpd package contains the core Apache web server, while httpd-tools provides useful utilities for testing and managing your Apache configuration. When prompted, confirm the installation by typing ‘y’ and pressing Enter.

DNF will automatically resolve and install any required dependencies. This process typically includes security libraries, configuration files, and system integration components necessary for Apache to function properly.

Post-Installation Verification

After installation completes, verify Apache was installed correctly by checking the installed version:

httpd -v

This command displays the Apache version and compilation information, confirming successful installation. The default Apache configuration files are located in /etc/httpd/, with the main configuration file at /etc/httpd/conf/httpd.conf.

Review the basic file structure to familiarize yourself with Apache’s organization on AlmaLinux. The document root directory defaults to /var/www/html/, where you’ll place your website files.

Starting and Enabling Apache Service

Once Apache is installed, you need to start the service and configure it to start automatically when your system boots.

Service Management

Start Apache immediately using systemctl, AlmaLinux’s service management utility:

sudo systemctl start httpd

To ensure Apache starts automatically after system reboots, enable the service:

sudo systemctl enable httpd

You can combine these commands for efficiency:

sudo systemctl enable --now httpd

This single command both enables the service for automatic startup and starts it immediately.

Service Configuration

Verify Apache is running correctly by checking its status:

sudo systemctl status httpd

A properly running Apache service displays “active (running)” in green text. If you see any errors or inactive status, review the error messages for troubleshooting guidance.

The Apache service integrates with systemd, providing advanced service management capabilities including automatic restart on failure and detailed logging through journald.

Firewall Configuration

AlmaLinux 10 includes firewalld by default, which blocks most incoming connections for security. You must configure the firewall to allow web traffic to reach your Apache server.

Opening Required Ports

Allow HTTP traffic on port 80 using firewalld commands:

sudo firewall-cmd --permanent --add-service=http

For HTTPS support, also open port 443:

sudo firewall-cmd --permanent --add-service=https

Apply the firewall changes by reloading the configuration:

sudo firewall-cmd --reload

Verify the rules were added successfully:

sudo firewall-cmd --list-services

Security Considerations

While opening these ports is necessary for web server functionality, consider implementing additional security measures for production environments. Use IP-based restrictions if you need to limit access to specific networks or addresses.

Monitor your firewall logs regularly to identify potential security threats or unusual access patterns. Consider implementing fail2ban or similar intrusion prevention systems for enhanced protection against brute-force attacks.

Testing Apache Installation

With Apache running and firewall configured, test your installation to ensure everything works correctly.

Basic Functionality Testing

Open a web browser and navigate to your server’s IP address. You should see the default AlmaLinux Apache test page, confirming successful installation. If you don’t know your server’s IP address, find it using:

ip addr show

The test page indicates Apache is properly serving content and accepting connections. This default page is served from /var/www/html/ and demonstrates basic Apache functionality.

Command-Line Testing

For headless servers or additional verification, test Apache using curl:

curl http://localhost

This command should return the HTML content of the default Apache test page. You can also verify Apache is listening on the correct ports:

sudo netstat -tlnp | grep httpd

Check Apache’s configuration syntax to ensure no errors exist:

sudo httpd -t

A response of “Syntax OK” indicates your configuration is valid.

Basic Apache Configuration

Understanding Apache’s configuration structure enables you to customize your web server for specific requirements and optimize performance.

Configuration File Management

Apache’s main configuration file is located at /etc/httpd/conf/httpd.conf. Before making changes, create a backup:

sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

Additional configuration files are stored in /etc/httpd/conf.d/, where you can add custom configurations without modifying the main file. This modular approach simplifies management and reduces the risk of configuration errors.

Always test configuration changes before applying them:

sudo httpd -t

If syntax errors exist, Apache will display specific error messages to help you identify and fix problems.

Document Root Configuration

The document root defines where Apache looks for website files. The default location is /var/www/html/. Create a simple test page:

sudo echo "<h1>Welcome to Apache on AlmaLinux 10</h1>" > /var/www/html/index.html

Set proper ownership and permissions:

sudo chown apache:apache /var/www/html/index.html
sudo chmod 644 /var/www/html/index.html

If SELinux is enabled, set appropriate security contexts:

sudo setsebool -P httpd_can_network_connect 1
sudo chcon -R -t httpd_exec_t /var/www/html/

Virtual Hosts Setup

Virtual hosts allow you to serve multiple websites from a single Apache installation, making efficient use of server resources and simplifying management.

Creating Virtual Host Structure

Create directories for each website you plan to host:

sudo mkdir -p /var/www/example.com/public_html
sudo mkdir -p /var/www/example.com/logs

Set appropriate ownership:

sudo chown -R apache:apache /var/www/example.com

Virtual Host Configuration

Create a configuration file for your virtual host in /etc/httpd/conf.d/:

sudo nano /etc/httpd/conf.d/example.com.conf

Add the following configuration, replacing example.com with your actual domain:

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/example.com/public_html
    ServerName example.com
    ServerAlias www.example.com
    ErrorLog /var/www/example.com/logs/error.log
    CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>

Test the configuration and restart Apache:

sudo httpd -t
sudo systemctl restart httpd

Security Hardening

Implementing proper security measures protects your Apache server from common attacks and unauthorized access.

Basic Security Measures

Hide Apache version information by adding these directives to your configuration:

ServerTokens Prod
ServerSignature Off

Disable unnecessary modules to reduce attack surface:

sudo nano /etc/httpd/conf/httpd.conf

Comment out modules you don’t need by adding ‘#’ at the beginning of LoadModule lines.

Advanced Security Configuration

For production environments, implement SSL/TLS encryption. Install SSL module and certificates:

sudo dnf install mod_ssl

Configure security headers in your virtual host:

Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"

Troubleshooting Common Issues

Understanding common Apache problems and their solutions helps maintain a stable web server environment.

Installation Problems

If package installation fails, verify your network connection and repository configuration. Clean the DNF cache and retry:

sudo dnf clean all
sudo dnf makecache
sudo dnf install httpd httpd-tools

Permission errors often indicate SELinux policy conflicts. Check SELinux status and logs:

getenforce
sudo ausearch -m avc -ts recent

Configuration Issues

Syntax errors in configuration files prevent Apache from starting. Use httpd -t to identify specific problems and their locations. Common issues include:

  • Missing closing tags in virtual host configurations
  • Incorrect file paths in DocumentRoot directives
  • Typos in directive names or values

Virtual host conflicts occur when multiple hosts use the same ServerName. Ensure each virtual host has a unique ServerName directive.

Maintenance and Best Practices

Regular maintenance ensures your Apache server remains secure, performant, and reliable over time.

Regular Maintenance Tasks

Update Apache and system packages regularly:

sudo dnf update httpd

Monitor log files for errors and security threats:

sudo tail -f /var/log/httpd/error_log

Implement log rotation to prevent disk space issues:

sudo logrotate -f /etc/logrotate.d/httpd

Optimization Recommendations

Monitor Apache performance using built-in status modules:

LoadModule status_module modules/mod_status.so
<Location "/server-status">
    SetHandler server-status
    Require local
</Location>

Configure appropriate MaxRequestWorkers based on your server’s resources and expected traffic. Monitor memory usage and adjust as needed.

Consider implementing caching mechanisms like mod_cache for improved performance with dynamic content.

Congratulations! You have successfully installed Apache web server. Thanks for using this tutorial for installing the Apache HTTP Server on your AlmaLinux OS 10 system. For additional help or useful information, we recommend you check the official Apache website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button