Configuring Virtual Host In Centos 7 VPS

Virtual host allows us to setup and configure multiple domain names on the same VPS server.
To configure virtual host you need at least one domain name.

To setup virtual host you need to create a virtual file in /etc/httpd/conf.d directory.
The file should be named according to your domain name and should end with .conf so if your domain name is example.com then the name of the file should be example.com.conf

Below is the code you need to put in your virtual host file replace example.com with your domain name

<VirtualHost *:80>
    DocumentRoot "/var/www/html/example.com"
    ServerName www.example.com
    ServerAlias example.com
   <Directory "/var/www/html/example.com">
    Options FollowSymLinks
    AllowOverride All
   Options -Indexes
    </Directory>
</VirtualHost>

If you are not sure about your server’s DocumentRoot then use the following command, it will display the DocumentRoot
grep -i ‘DocumentRoot’ /etc/httpd/conf/httpd.conf
If you are using a domain specific directory for the domain name for which you are creating the virtual host then include that in the DocumentRoot.
Note that example.com in /var/www/html/example.com is the domain specific directory, you can create a new directory for your domain and name it anything you want but naming it according to your domain name helps to keep things organized.

Still confused ? (Then watch the video)
In the video below you will learn how to setup virtual host for your domain name in Centos vps.

Previous Post
Installing PHP 7.x on Centos 7
Next Post
How to install wordpress using SSH on Centos 7 VPS

Related Posts

1 Comment. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

alert('dsf'); console.log("dsdsdsd");