Table of Contents
Why Setup Virtual Host:
Setting up a virtual host allows you to use an alias name for your localhost. We can set up multiple virtual host as per our need so that each local website can be accessed through a specific name.
let’s say your site resides in “http://localhost/site1” and you want to load all the assets. There is always an issue when we follow traditional steps like creating a folder inside “..\xampp\htdocs\site1”. This is the place where we used to place our hosting site in Windows, and always get an issue when they want to fetch any file resides in that directory.
In this case, the URL becomes “http://localhost:8012/site1/sites/default/files/image.jpg”. Due to an invalid path, files become inaccessible and as a result, they won’t get loaded on the page.
Steps for creating Virtual Host
Open httpd.conf file present in C:\xampp\apache\conf\httpd.conf
Remove the #(hash) sign present to include the “httpd-vhosts.conf” file in httpd.conf file.
# Virtual hosts
# Virtual hosts
Create a virtualhost file. Open “httpd-vhosts.conf” file. And copy the below lines of code.
ServerAdmin [email protected]
ServerName <SERVER_NAME like local.pos.com>
Replace PATH_TO_PROJECT_DIRECTORY_HERE & SERVER_NAME with appropriate values, Save the file.
Add the below line at the end of the file.
127.0.0.1 <SERVER_NAME like local.pos.com>
Restart the apache server and visit the site URL.
That’s all that is needed to set up a virtual host.
Best hosting Servers:
Are you looking for the best hosting server, cheap web hosting?
Check some of the best hostings recommendations
Are you looking for VPS hosting?
Check our Compare WebService
[…] See this for reference: https://ultimatefosters.com/hosting/setup-a-virtual-host-in-windows-with-xampp-server/ […]
[…] Apache VirtualHost Setting Up […]