CentOSRHEL Based

How To Install Apache on CentOS Stream 10

Install Apache on CentOS Stream 10

Apache HTTP Server, commonly referred to as Apache, is one of the most widely used web servers in the world. It is known for its robustness, flexibility, and extensive features that cater to both small and large-scale web applications. This article provides a comprehensive guide on how to install Apache 2.4 on CentOS Stream 10, ensuring that you can set up a reliable web server environment for your projects.

Understanding Apache HTTP Server

What is Apache HTTP Server?

Apache HTTP Server is an open-source web server software that enables users to serve web content over the internet. It supports various operating systems and is known for its modular architecture, allowing users to extend its functionality through additional modules. Key features include:

  • Support for multiple programming languages and frameworks.
  • Robust security features including SSL/TLS support.
  • Highly configurable through text-based configuration files.

Why Choose Apache 2.4?

Apache 2.4 introduces several enhancements over previous versions, particularly in terms of performance and resource management. Some notable improvements include:

  • Better handling of concurrent connections.
  • Improved caching mechanisms.
  • Enhanced security features, including better support for modern protocols.

Compatibility with CentOS Stream 10

CentOS Stream serves as a rolling release distribution, providing a preview of what the next minor release of RHEL (Red Hat Enterprise Linux) will look like. This makes it an excellent choice for developers and system administrators who want to stay ahead of the curve while ensuring stability and support.

Prerequisites for Installation

System Requirements

Before installing Apache, ensure your system meets the following minimum hardware specifications:

  • Processor: 1 GHz or faster
  • RAM: At least 1 GB (2 GB recommended)
  • Disk Space: Minimum of 10 GB available

Software Requirements

Your CentOS Stream 10 installation should be updated to ensure all packages are current. Use the following command:

sudo dnf update

User Permissions

You will need root or sudo access to install and configure Apache. If you are not logged in as root, prepend commands with sudo.

Setting Up the Environment

Updating the System

The first step in preparing your system for Apache installation is to update your package manager’s cache and installed packages:

sudo dnf update -y

Installing Required Dependencies

You may need to enable the EPEL (Extra Packages for Enterprise Linux) repository, which contains additional packages that might be required by Apache:

sudo dnf install epel-release -y

Installing Apache 2.4

Using DNF to Install Apache

The installation process for Apache on CentOS Stream 10 is straightforward. Execute the following command:

sudo dnf install httpd -y

Verifying Installation

After installation, confirm that Apache was installed correctly by checking its version:

httpd -v

You should see output indicating the version of Apache installed, confirming a successful installation.

Configuring Apache

Basic Configuration Files

The main configuration file for Apache is located at /etc/httpd/conf/httpd.conf. This file contains settings that control how the server behaves. It’s essential to back up this file before making any changes:

sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

Setting Up Document Root

The default document root for your website is typically located at /var/www/html/. You can change this location by editing the DocumentRoot directive in the configuration file:

# Open the configuration file
sudo vi /etc/httpd/conf/httpd.conf

# Find and modify the DocumentRoot line
DocumentRoot "/var/www/html"
# Save and exit

Configuring Virtual Hosts

If you plan to host multiple websites on a single server, configuring virtual hosts is essential. Create a new configuration file for each site in the /etc/httpd/conf.d/ directory:

# Create a new virtual host configuration
sudo nano /etc/httpd/conf.d/example.conf

# Add the following basic configuration

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log
</VirtualHost>

# Save and exit

Starting and Enabling Apache Service

Starting the Apache Service

The next step is to start the Apache service using systemctl:

sudo systemctl start httpd.service

Enabling Apache to Start at Boot

If you want Apache to start automatically when your server boots up, use this command:

sudo systemctl enable httpd.service

Firewall Configuration

Opening Ports for HTTP and HTTPS

A firewall may block incoming traffic on ports 80 (HTTP) and 443 (HTTPS). To allow traffic through these ports, execute the following commands:

# Allow HTTP traffic
sudo firewall-cmd --permanent --add-service=http

# Allow HTTPS traffic
sudo firewall-cmd --permanent --add-service=https

# Reload firewall rules
sudo firewall-cmd --reload

Testing the Installation

Accessing Apache from a Browser

You can test if Apache is running correctly by opening a web browser and navigating to your server’s IP address or domain name (e.g., http://your-server-ip). You should see the default Apache test page indicating that your installation was successful.

Checking Server Status

You can monitor whether the Apache service is running properly with this command:

sudo systemctl status httpd.service

Troubleshooting Common Issues

Common Installation Errors

If you encounter issues during installation or startup, consider these common problems:

  • Error: “httpd: Syntax error on line …”: This indicates a syntax error in your configuration files. Review recent changes carefully.
  • Error: “Could not bind to address …”: This error means another service is already using port 80 or 443. Use snetstat -tuln | grep :80 (or :443) to find out which service it is.
  • Error: “Service not found”: Ensure that you have installed httpd correctly and that you are using correct service names in commands.

Logs for Debugging

If issues persist, check the error logs located at /var/log/httpd/error_log. This log file provides detailed information about any errors encountered by Apache during operation.

Congratulations! You have successfully installed Apache HTTP Server. Thanks for using this tutorial for installing Apache web server on CentOS Stream 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