How to Setup Apache with a Virtual Host in CentOS 9 Stream

How to Setup Apache with a Virtual Host in CentOS 9 Stream

To setup Apache with a virtual host in CentOS 9 Stream, you can follow these steps:

Guide To Configuring Apache With A Virtual Host

Install Apache

Example
sudo dnf install httpd

Start the Apache service

Example
sudo systemctl start httpd

Enable Apache to start on boot

Example
sudo systemctl enable httpd

Configure the virtual host

Create a new configuration file for your virtual host. For example, create a file named mydomain.conf in the /etc/httpd/conf.d/ directory:

Example
sudo nano /etc/httpd/conf.d/mydomain.conf

Add the following content to the file. Replace example.com with your domain name and /var/www/html/example with the path to your website’s files:

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

Save the file and exit the text editor.

Adjust firewall settings if necessary

If you have firewalld enabled, allow HTTP traffic:

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

Finally, update your DNS settings to point your domain to the server’s IP address.

Your virtual host should now be set up and accessible through the specified domain name. Make sure you have the necessary files in the specified document root directory to serve your website content.

Related Articles

Notice an error?

Help us improve our content by reporting any issues you find.