Skip to content

Creating Virtual Hosts for Multiple Domain Names on Apache Web Server with AlmaLinux 9

Guide on setting up Apache Virtual Hosts in AlmaLinux 9 for managing numerous websites with distinct domain names.

Creating Virtual Hosts for Multiple Domain Names on Apache Web Server with AlmaLinux 9
Creating Virtual Hosts for Multiple Domain Names on Apache Web Server with AlmaLinux 9

Creating Virtual Hosts for Multiple Domain Names on Apache Web Server with AlmaLinux 9

In today's digital age, hosting multiple websites on a single server can significantly reduce costs and maximise efficiency. Here's a step-by-step guide on how to configure name-based virtual hosting on an Apache Web Server running on AlmaLinux 9.

Firstly, ensure that Apache (httpd) is installed if not already present:

```bash sudo dnf install httpd -y ```

Next, create Virtual Host Configuration Files by navigating to the Apache configuration directory for virtual hosts:

```bash cd /etc/httpd/conf.d/ ```

Create a new virtual host config file, for example, `example1.conf`:

```bash sudo vi /etc/httpd/conf.d/example1.conf ```

Add the following content to configure the virtual host:

```apache

ErrorLog /var/log/httpd/example1-error.log CustomLog /var/log/httpd/example1-access.log combined ```

Repeat for each website you want to host, with different `ServerName` and `DocumentRoot` paths, e.g., `example2.conf` with `ServerName www.example2.com` and a different `DocumentRoot`.

Prepare Document Roots and set permissions:

```bash sudo mkdir -p /var/www/html/example1 sudo chown -R apache:apache /var/www/html/example1 sudo chmod -R 755 /var/www/html/example1 ```

Repeat for each site.

For local testing, modify the `/etc/hosts` file:

```bash 127.0.0.1 www.example1.com www.example2.com ```

Restart the Apache service to apply the new configuration:

```bash sudo systemctl restart httpd ```

Allow HTTP through the firewall:

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

Finally, test your configuration by navigating to http://www.example1.com and http://www.example2.com (adjust DNS or hosts file accordingly).

To secure websites with SSL, consider installing Certbot and the Apache SSL module. Additionally, ensure there are no syntax errors in the configuration files and add basic HTML content to the created files.

This method follows standard Apache virtual host configuration documented in related CentOS/RHEL contexts and is fully applicable to AlmaLinux 9, which is binary compatible with RHEL 9. The key is creating separate `

This setup is consistent with Apache's documented behavior and practices used in AlmaLinux 9 environments, leveraging the same configuration paths and systemctl commands as CentOS/RHEL systems.

Data from this tutorial can assist software developers in creating multiple website hosting solutions, reducing costs and improving efficiency. In the realm of general-news and lifestyle, this technology-driven approach revolutionizes the way we manage and host diverse websites, paving the way for a more connected digital lifestyle.

Read also:

    Latest