Dec 02, 2025
Edgaras G.
2min Read
If you want to host more than one domain on your server, you need to create corresponding hosts on the webserver. That way, your server can deliver different content for different requests. In this tutorial, you will learn how to create Apache virtual hosts on CentOS 9 Stream.
Before we begin, make sure that you have root access to your VPS or server using an SSH connection. If you’re using Hostinger’s hPanel, you will find your login credentials near the top of the Overview page.

sudo yum -y install httpd
sudo systemctl enable httpd.service

cd /var/www/
mkdir -p yourdomain.com/public_html
Remember to replace yourdomain.com with your actual domain name.
chown -R apache:apache /var/www/yourdomain.com/public_html chmod -R 755 /var/www
Apache now has the required access to create additional directories and serve content for incoming queries.
It is recommended that you make a demo page for your Apache virtual hosts. This way, you can check whether the host is working before you actually move your website files. Here’s how you do it:
nano yourdomain.com/public_html/index.html
<html> <head> <title>This is a test page</title> </head> <body> <h1>It works!</h1> </body> </html>
nano /etc/httpd/conf.d/yourdomain.com.conf
<VirtualHost *:80> ServerName www.yourdomain.com ServerAlias yourdomain.com DocumentRoot /var/www/yourdomain.com/public_html ErrorLog /var/www/yourdomain.com/error.log CustomLog /var/www/yourdomain.com/requests.log combined </VirtualHost>
In the example above, we tell Apache that we will be using port 80 for the communication and that yourdomain.com is the name of the virtual host. Additionally, we also specify directories for the website files (document root) and error logs.
systemctl restart httpd.service
And that’s it – you have just created an Apache virtual host for your domain! Now try to access the host, and you should see the “It works!” text on the demo page we made earlier.
You have learned how to create an Apache virtual host in four easy steps. To summarize, let’s take a look at them once again:
We hope you’ve found this tutorial useful. Feel free to comment below if you have any questions!
