First, ensure that Apache is installed on your CentOS 9 system.
Virtual Hosts are defined within configuration files with a .conf extension
Create a new file
vi /etc/httpd/conf.d/mydomain.com.conf
In this file, you’ll set up a block for your domain:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain
ErrorLog /var/log/httpd/mydomain-error.log
</VirtualHost>
Check for syntax errors after configuring your virtual hosts
apachectl configtest
If you get a ‘Syntax OK’ output, restart apache to apply the changes:
systemctl restart httpd
Setup local hosts file
If you’re testing your configuration locally, edit your /etc/hosts file to point the domain to your local server
127.0.0.1 mydomain.com www.mydomain.com