How to create virtual hosts on Apache (httpd) on CentOs 7

Using virtual hosts on Apache allows you to host multiple websites on one server. In order for virtual hosts to function correctly you will need to insure that you have DNS set up correctly for your sites. If you are following this tutorial for test purposes you can reference this video on how to manually set DNS on a Centos Server:

If you need to know how to install apache on CentOs you can reference this video:

The commands that you need to follow this video are:

cd /var/www/html/
sudo mkdir site1
sudo mkdir site2

sudo chown apavhe:apache -R site1
sudo chown apavhe:apache -R site2

sudo vi site1/index.html
sudo vi site2/index.html

cd /ete/httpd/
sudo mkdir sites-available
sudo mkdir sites-enabled

sudo vi /etc/httpd/conf/httpd.conf

Add this line to the end of your file:

IncludeOptional sites-enabled/*.conf

cd sites-avaiable

sudo vi site1.com.conf

<VirtualHost *:80>

ServerName www.site1.com
ServerAlias site1.com
DocumentRoot /var/www/html/site1/
ErrorLog /var/www/html/site1/error.log
CustomLog /var/www/html/site1/requests.log combined
</VirtualHost>

sudo cp site1.com.conf site2.com.conf

sudo vi site2.com.conf

<VirtualHost *:80>

ServerName www.site2.com
ServerAlias site2.com
DocumentRoot /var/www/html/site2/
ErrorLog /var/www/html/site2/error.log
CustomLog /var/www/html/site2/requests.log combined
</VirtualHost>

sudo ln -s /etc/httpd/sites-available/site1.com.conf /etc/httpd/sites-enabled/site1.com.conf
sudo ln -s /etc/httpd/sites-available/site2.com.conf /etc/httpd/sites-enabled/site2.com.conf

sudo service httpd restart

Disable selinux

sudo setenfoce 0

 

This entry was posted in CentOS, Computer Science, linux. Bookmark the permalink.

4 Responses to How to create virtual hosts on Apache (httpd) on CentOs 7

  1. Pingback: How to create virtual hosts on Apache (httpd) on CentOs 7 | Host your Website

  2. Pingback: How to create virtual hosts on Apache (httpd) on CentOs 7 – My blog

  3. SHAFEEQ says:

    I followed all the steps but in browser it keeps loading and times out…

  4. AYUK ROLAND AGBOR says:

    hello Daren
    Thank you for such wonderful sense of knowledge you put on medias like this. It has helped me solved my problems of hosting multiple websites on a single server.

    You will just have to make a check up on those codes. some are not written correctly, for example you wrote apache as apavhe

Leave a Reply

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