Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»How to Install Apache (httpd) on RHEL & CentOS Stream 9

    How to Install Apache (httpd) on RHEL & CentOS Stream 9

    By RahulFebruary 9, 20234 Mins Read

    Apache is one of the most popular open-source web servers available today, offering a robust set of features and high performance. In this article, we’ll show you how to install Apache on RHEL & CentOS Stream 9 and then secure it for production use.

    Advertisement

    Prerequisites

    Before getting started, you’ll need to have access to a server running RHEL & CentOS Stream 9. You should also have root or sudo privileges so that you can install packages and make changes to the system. Additionally, you’ll need to have a basic understanding of Linux commands and how to use a text editor such as nano or vim.

    Step 1: Installing Apache

    To install Apache, you’ll first need to add the EPEL repository to your system. This can be done with the following command:

    sudo dnf install epel-release 
    

    Next, you can install Apache using the following command:

    sudo dnf install httpd 
    

    Once the installation is complete, you can start Apache with the following command:

    sudo systemctl start httpd 
    

    To ensure that Apache starts automatically at boot time, run the following command:

    sudo systemctl enable httpd 
    

    Step 2: Testing the Installation

    To test the installation, open a web browser and navigate to `http://your-server-ip`. You should see a page that says “Welcome to your Apache Web Server”. This confirms that Apache is up and running on your system.

    How to Install and Secure Apache on RHEL & CentOS Stream 9
    Installing Apache (httpd) web server

    Step 3: Securing Apache

    Now that Apache is installed, it’s time to secure it for production use. Here are some key steps to follow:

    1. Update Apache to the latest version
    2. It’s important to keep your Apache installation up to date in order to take advantage of security fixes and other improvements. You can update Apache using the following command:

      sudo dnf update httpd 
      

    3. Disable directory listing
    4. By default, Apache will display a directory listing if no index file is present in a directory. This can be a security risk, so it’s best to disable directory listing. You can do this by adding the following lines to the Apache configuration file located at /etc/httpd/conf/httpd.conf:

      1
      2
      3
      <Directory /var/www/html>
      Options -Indexes
      </Directory>

    5. Configure a firewall
    6. A firewall can help protect your server from unauthorized access by blocking incoming traffic on certain ports. On RHEL & CentOS Stream 9 , you can use the built-in firewall service, firewalld, to control incoming traffic. To allow traffic to Apache, run the following command:

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

    7. Enable SSL/TLS encryption
    8. In order to encrypt data transmitted between the server and clients, you should enable SSL/TLS encryption. This can be done by obtaining an SSL certificate and configuring Apache to use it. A self-signed certificate can be created using the following command:

      sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache.key -out /etc/ssl/certs/apache.crt 
      

      Next, you need to configure Apache to use the certificate. This can be done by adding the following lines to the Apache configuration file located at /etc/httpd/conf/httpd.conf:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      <VirtualHost _default_:443>
          DocumentRoot "/var/www/html"
          ServerName your-server-name
       
          SSLEngine on
          SSLCertificateFile /etc/ssl/certs/apache.crt
          SSLCertificateKeyFile /etc/ssl/private/apache.key
       
          <Directory "/var/www/html">
              Options Indexes FollowSymLinks
              AllowOverride None
              Require all granted
          </Directory>
      </VirtualHost>

      Restart Apache after making these changes using the following command:

      sudo systemctl restart httpd 
      

    9. Limit access to sensitive files
    10. It’s important to limit access to sensitive files such as configuration files and logs. You can do this by adding the following lines to the Apache configuration file located at /etc/httpd/conf/httpd.conf:

      1
      2
      3
      <FilesMatch "\.(log|cfg)$">
          Require all denied
      </FilesMatch>

    Conclusion

    By following the steps outlined in this article, you have successfully installed and secured Apache on RHEL & CentOS Stream 9. These are just some of the basic steps to secure your Apache installation, and you should always stay up-to-date on security best practices and developments in the field to ensure that your server remains secure. Additionally, it’s important to regularly monitor your Apache logs and keep an eye out for any signs of malicious activity or security incidents. With the right precautions in place, you can ensure that your Apache server is running smoothly and securely.

    Apache CentOS 9 httpd web-server
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Apache with PHP-FPM on Ubuntu 22.04

    Configuring Nginx to Handle 100 Thousands Request Per Minute

    Configuring Nginx to Handle 100 Thousands Request Per Minute

    Comparing Apache MPM Worker and Prefork: Which is Right for Your Application

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Python Lambda Functions – A Beginner’s Guide
    • 10 Practical Use Cases for Lambda Functions in Python
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.