Showing posts with label Vertual Host. Show all posts
Showing posts with label Vertual Host. Show all posts

Wednesday, June 8, 2016

Host more than one website from your own local system.



In my last post: Install XAMPP server, test and run a website on your own local system. I told you about installing a server on your system and creating and testing a simple website from your own system. That was to host a single website from one system, now we learn about hosting multiple websites from one system. This can be done by Virtual Host. Virtual Host means to host more than one website on single machine.  To host multiple websites, you have to create separate folders for each website in the htdocs folder.  Like if you want to websites mysite1, mysite2…….., create folders like
C:\XAMPP\htdocs\mysite1, C:\XAMPP\htdocs\mysite2 …………
Now create individual index.php files for mysite1, mysite2…….
Next tell apache to host multiple websites, for this we have to configure httpd-vhosts file in apache which is in the folder C:\XAMPP\apache\conf\extra. Open the file with note pad or other editor. This file will look like :



Now add the following lines in the last of file without deleting anything from the file:

<VirtualHost *:80>  
DocumentRoot "C:\XAMPP\htdocs\mysite1"
ServerName www.mysite1.com
</VirtualHost>

<VirtualHost *:80>  
DocumentRoot "C:\XAMPP\htdocs\mysite2"
ServerName www.mysite2.com
</VirtualHost>

Now the httpd-vhosts file looks like:


After having done editing with apache, we have to modify host file in the directory C:\Windows\System32\Drivers\etc\hosts
Add the following lines in the last of file:
127.0.0.1 www.mysite1.com
127.0.0.1 www.mysite2.com


After updating the hosts file and httpd-vhost file, restart all the services of XAMPP. And now you have different websites hosted from your own computer with your own server.