This guide will walk you through setting up virtual hosts to run multiple websites on a single server and installing Apache on AlmaLinux 9.2. Whether you’re running a personal blog, a small business website, or a complex web application, having a robust web server is essential. Apache, one of the most popular and reliable web servers available, can help you achieve this.
Requirements
Let’s make sure you have everything you need before we start the installation process:
- AlmaLinux 9.2 Virtono Server: Make sure you have AlmaLinux 9.2 installed on your server. If not, you can download it from the official AlmaLinux website.
- Root or Sudo Access: You’ll need root or sudo access to execute commands with administrative privileges.
- Basic Command Line Skills: Familiarity with the Linux command line will be helpful.
- Domain or Subdomains: Decide on the domain names or subdomains you want to host on your server.
Installing Apache on AlmaLinux 9.2
To get started, log in to your AlmaLinux server and follow these steps:
Step 1: Update the System
Update your system’s package repositories and upgrade any existing packages before installing Apache. Run the following commands:
sudo dnf update
This will ensure that your system is up to date with the latest security patches and software updates.
Step 2: Install Apache on AlmaLinux 9.2
To install Apache on AlmaLinux 9.2, use the following command:
sudo dnf install httpd
After entering this command, the system will prompt you to confirm the installation. Type ‘y’ and press Enter to proceed. AlmaLinux will then download and install Apache on your server.
Step 3: Start and Enable Apache
Once the installation is complete, start the Apache on AlmaLinux 9.2 service and enable it to start automatically at boot:
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
Step 4: Configure the Firewall
You must permit HTTP traffic to pass through your server’s firewall if it is enabled. Use the following command to do this:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Step 5: Verify Apache Installation
Open a web browser and type the IP address or domain name of your server to check that Apache on AlmaLinux 9.2 is operational. The Apache default page should appear, indicating a successful installation.
Configuring Virtual Hosts
Now that Apache is installed let’s configure virtual hosts to host multiple websites on a single server.
Step 1: Create a Directory Structure
It’s a good practice to create a directory structure for your virtual hosts. This will help keep your configuration organized. For example, you can create a directory for each website under the /var/www
directory:
sudo mkdir -p /var/www/example.com/public_html
sudo mkdir -p /var/www/anotherdomain.com/public_html
Replace example.com
and anotherdomain.com
with your actual domain names.
Step 2: Set Permissions
Set the proper permissions to make sure Apache can serve files from these directories:
sudo chown -R apache:apache /var/www/example.com
sudo chown -R apache:apache /var/www/anotherdomain.com
Step 3: Create Virtual Host Configuration Files
To manage virtual hosts, Apache uses configuration files. Each virtual host can have its own configuration file. Create a configuration file, for example.com:
sudo nano /etc/httpd/conf.d/example.com.conf
Add the following details to the configuration file:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/log/httpd/example.com_error.log
CustomLog /var/log/httpd/example.com_access.log combined
</VirtualHost>
This configuration tells Apache to serve files from the /var/www/example.com/public_html
directory when a request comes in for example.com
. Don’t forget to replace example.com
with your actual domain name.
After creating or modifying the virtual host configuration, restart Apache to apply the changes:
sudo systemctl restart httpd
Final Thoughts
This tutorial has shown you how to install Apache on AlmaLinux 9.2 and set up virtual hosts to host multiple websites. This configuration makes hosting multiple web projects cost-effective because it enables you to effectively manage and serve multiple websites from a single server. To keep your websites secure and functioning properly, keep your server’s security updated and maintained on a regular basis. With Apache and AlmaLinux, you’re well on your way to creating a powerful and versatile web hosting environment.
0 Comments