Apache2.4.6 (CentOS 7) – Create Virtual Hosts

The instructions below show how to create virtual hosts in Centos 7. In this case the virtual hosts will be running from a custom location in the system and not from directories created in the /home directory.

Edit/Create your Virtual Host file
Create/edit the following file by entering the following line. This will tell httpd to read the configuration for the actual virtual hosts, provided of course that the main httpd.conf file is instructed (usually by default) to read the files in ‘conf.d/*.conf’ directory.

vim /etc/httpd/conf.d/vhosts.conf
IncludeOptional vhosts.d/*.conf

Create the directory where the config files for the Virtual Hosts will reside.

mkdir /etc/httpd/vhosts.d

Create the config file for your first Virtual Host.

vim /etc/httpd/vhosts.d/rpmsrepo.sfentona.lol.conf

Include the following lines in the config file.

<VirtualHost *:80>
 ServerAdmin webmaster@dummy-host.example.com
 DocumentRoot /repo/Centos06/centos/
 ServerName rpmsrepo.sfentona.lol
 ServerAlias www.rpmsrepo.sfentona.lol

<Directory "/repo/Centos06/centos/">
 DirectoryIndex index.html index.php
 Options FollowSymLinks
 AllowOverride All
 Require all granted

Create the directories where your virtual hosts will be running from
mkdir /repo/Centos06/centos/
chown -R apache:apache /repo/Centos06/centos/
chmod 755  /repo/Centos06/centos/

Check your httpd configuration and start httpd

apachectl configtest
systemctl restart httpd
systemctl status httpd
Share Button