top of page

Group

Public·435 members

ijaz Ahmed
ijaz Ahmed

How to Install Apache Webserver on Rocky Linux 9

How to Install Apache Webserver on Rocky Linux 9

Apache HTTP Server, commonly referred to as Apache, is one of the most popular and widely used web servers globally. Apache serves websites and web applications by handling requests from clients and delivering web pages. Installing Apache on Rocky Linux 9 is a straightforward process and can be completed in a few steps.

In this guide, we will walk you through the installation process of Apache Web Server on Rocky Linux 9 and configure it to run smoothly.

Prerequisites:

Before starting the installation process, make sure you have the following:

  1. Rocky Linux 9 system with a non-root user having sudo privileges.

  2. Internet connection to download the Apache package.

  3. Firewall access: Ensure the necessary ports are open (HTTP: 80, HTTPS: 443).

Step 1: Update Your System

First, ensure that your system is up to date with the latest software packages. This is always recommended before installing any new software.

Open the terminal and run the following command:

bash

CopyEdit

sudo dnf update -y

This will update all installed packages to the latest available version.

Step 2: Install Apache Web Server (httpd)

Now, let’s install Apache using the default Rocky Linux package manager dnf.

  1. Install Apache by running the following command:

bash

CopyEdit

sudo dnf install httpd -y

This command will download and install the Apache HTTP Server package.

  1. Once the installation is complete, you can verify it by checking the version of Apache:

bash

CopyEdit

httpd -v

You should see output like:

bash

CopyEdit

Server version: Apache/2.4.51 (Rocky Linux) Server built: ...

Step 3: Start and Enable Apache Service

After the installation, you need to start the Apache service and ensure that it starts automatically at boot time.

  1. Start the Apache service with the following command:

bash

CopyEdit

sudo systemctl start httpd

  1. Enable Apache to start automatically at boot:

bash

CopyEdit

sudo systemctl enable httpd

Step 4: Adjust Firewall Settings

If your system has a firewall enabled, you need to open ports 80 (HTTP) and 443 (HTTPS) to allow incoming traffic for your web server.

  1. To allow HTTP traffic, run the following command:

bash

CopyEdit

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

  1. To allow HTTPS traffic (for secure connections), run:

bash

CopyEdit

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

  1. Reload the firewall settings to apply the changes:

bash

CopyEdit

sudo firewall-cmd --reload

Step 5: Verify Apache Installation

Once Apache is installed and running, you can verify it by accessing your server's IP address from a web browser.

  1. Find your server's public IP address:

bash

CopyEdit

ip addr show

  1. Open a web browser and type your server’s IP address:

text

CopyEdit

http://your-server-ip

If everything is set up correctly, you should see the default Apache test page saying "It works!".

Step 6: Configure Apache (Optional)

Apache can be configured to suit your needs. Some of the common configuration steps include:

  1. Edit Apache configuration file:Apache’s main configuration file is located at /etc/httpd/conf/httpd.conf. You can open and edit it using any text editor, for example:bashCopyEditsudo nano /etc/httpd/conf/httpd.conf

  2. Create Virtual Hosts:You can configure virtual hosts to host multiple websites on a single server. This is useful if you have multiple domains or websites to serve.To create a new virtual host, you’ll typically create a new .conf file in /etc/httpd/conf.d/ or edit the default configuration file.Example for a basic virtual host:apacheCopyEdit<VirtualHost *:80> ServerAdmin webmaster@yourdomain.com DocumentRoot /var/www/html/yourwebsite ServerName yourdomain.com ErrorLog /var/log/httpd/yourwebsite_error.log CustomLog /var/log/httpd/yourwebsite_access.log combined </VirtualHost>After editing the configuration file, restart Apache to apply changes:bashCopyEditsudo systemctl restart httpd

Step 7: Secure Apache (Optional)

To enhance the security of your Apache server, you can configure SSL/TLS encryption for HTTPS.

  1. Install Certbot (for Let’s Encrypt SSL certificate):Run the following command to install Certbot:bashCopyEditsudo dnf install certbot python3-certbot-apache -y

  2. Obtain an SSL certificate:You can now obtain a free SSL certificate from Let’s Encrypt using Certbot:bashCopyEditsudo certbot --apacheFollow the prompts to configure SSL for your domain.

Step 8: Check Apache Service Status

You can always check the status of the Apache service to ensure it's running properly:

bash

CopyEdit

sudo systemctl status httpd

This command will show you whether the Apache service is active or inactive.

1 View

Members

Subscribe Form

Thanks for submitting!

  • LinkedIn

©2024 by Christina Bardine. Proudly created with Wix.com

bottom of page