fbpx

In this step-by-step guide, we will walk you through the process of installing Apache on AlmaLinux 9.1. Additionally, we will explore how to configure virtual hosts, which allow you to host multiple websites on a single Apache installation. Apache is a widely-used and highly popular web server that powers a significant portion of websites on the internet. By following this tutorial, you’ll have Apache up and running, along with virtual hosts configured, on your AlmaLinux server.

Install Apache on AlmaLinux 9.1

Step 1: Update the System

Before installing any new software, it’s always recommended to update your system to ensure you have the latest security patches and software updates. Open a terminal or SSH into your AlmaLinux server and run the following command:

sudo dnf update

This process may take a few minutes, depending on your internet connection speed and the number of updates available.

Apache on AlmaLinux 9.1

Step 2: Install Apache on AlmaLinux

Once the system update is complete, you can proceed with installing the Apache on AlmaLinux web server. AlmaLinux uses the DNF package manager, which makes the installation process straightforward. Run the following command in the terminal:

sudo dnf install httpd

Confirm the installation by typing ‘y’ when prompted and wait for the installation to finish. Apache and its dependencies will be downloaded and installed on your system.

Apache on AlmaLinux 9.1

Step 3: Start and Enable Apache

After the installation is complete, you need to start the Apache service and enable it to start automatically at system boot. Run the following commands:

sudo systemctl start httpd
sudo systemctl enable httpd

These commands will start the Apache on AlmaLinux service and configure it to start on boot. You can verify if Apache is running by visiting your server’s IP address in a web browser. If everything is working correctly, you should see the default Apache test page.

Step 4: Configure Firewall

By default, AlmaLinux 9.1 comes with the firewalld service enabled. You need to allow HTTP traffic through the firewall to access your Apache web server. Run the following command to enable HTTP traffic:

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

These commands will open port 80 for HTTP traffic, and the changes will persist across system reboots.

Step 5: Add Virtual Hosts

To host multiple websites on your Apache on AlmaLinux server, you can set up virtual hosts. Each virtual host represents a different website with its own domain or subdomain. Here’s how you can add virtual hosts:

Create a Directory Structure:

Create a directory to store your website files. For example, let’s create a directory named ‘mywebsite’ inside the ‘/var/www/html/’ directory:

sudo mkdir /var/www/html/mywebsite

Configure a Virtual Host:

Create a virtual host configuration file using a text editor. For example, create a file named ‘mywebsite.conf’ in the ‘/etc/httpd/conf.d/’ directory:

sudo nano /etc/httpd/conf.d/mywebsite.conf

Add the following content to the file:

<VirtualHost *:80>
    ServerName mywebsite.com
    DocumentRoot /var/www/html/mywebsite
    
    <Directory /var/www/html/mywebsite>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Replace ‘mywebsite.com’ with yourdesired domain or subdomain name, and ‘/var/www/html/mywebsite’ with the actual path to your website files.

Save the file and exit the text editor.

Enable the Virtual Host:

Enable the virtual host configuration by creating a symbolic link to the ‘mywebsite.conf’ file in the ‘/etc/httpd/conf.d/’ directory:

sudo ln -s /etc/httpd/conf.d/mywebsite.conf /etc/httpd/conf.d/

Step 6: Test the Virtual Host

To test the virtual host configuration, open a web browser and enter your virtual host’s domain or subdomain name. If everything is set up correctly, you should see your website’s content.

Final Thoughts

Congratulations! You have successfully installed Apache on AlmaLinux 9.1 and configured virtual hosts to host multiple websites. Apache on AlmaLinux is now ready to serve your websites and web applications. You can repeat Step 5 for each additional virtual host you want to add. Explore the Apache documentation to learn more about advanced configuration options and security best practices. Happy web serving!


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.