Short steps to create virtual host(s) on windows
Welcome... I am about to walk you through some simple steps on how you can setup virtual host(s) on your local machine(windows) using xampp/wampp.
Step 1: Edit httpd.conf • If and only if it is necessary, change xampp/wamp port. I have decided to use the default setting which is “Listen 80” How to: Click on Config -> Apache (httpd.conf) Or you find the file here C:\XAMPP\apache\conf\httpd.conf OR C:\XAMPP\apache2\conf\httpd.conf Change the line with “Listen 80” to “Listen 8080” or any other free ports. NOTE: “Listen 80” is usually the default port setting.
Step 2: Setting up virtual host(s) • Create a folder for your projects; I have created one in c:\vhost you can call it any name as you please. • In c:\vhost folder we’d create a sub-folder job1 or any other, it is up to you (c:\vhost) • Open httpd-vhosts.conf file C:\XAMPP\apache\conf\extra\httpd-vhosts.conf Add following code in line depending on how many virtual host you wish to create:
<Directory C:/vhost>
AllowOverride All
Require all granted
</Directory>
# XAMPP default address
<VirtualHost *:80>
DocumentRoot "C:/vhostjob1/"
ServerName job1.localhost
</VirtualHost>
# First virtual host address in XAMPP
<VirtualHost *:80>
DocumentRoot "C:/vhost/project1/"
ServerName php.localhost
SetEnv NS_ENV variable_value
</VirtualHost>
NOTE: More Virtual host address can be added here.
Save and close the file after the above steps.
Step 3: Edit Windows Host file • Stop Apache and MySQL services from XAMPP/WAMP. • Open hosts file in C:\windows\system32\drivers\etc you need Administrator privilege to edit the file. I suggest to edit the file directly with Sublime text editor. • Add 127.0.0.1 job1.localhost at the end of the file, Save and close the file. • save the file
Step 4: Start/Re-start your Apache and MySQL again. Giveaway tip -- Open file php.ini under php folder in your Apache (XAMPP or WAMP) folder and change opcache.enable to 0 so it looks like this: [opcache] zend_extension=php_opcache.dll ; Determines if Zend OPCache is enabled opcache.enable=0
Step 5: Goto your browser and type : job1.localhost
I hope this helps you solve a problem. Feel free to contact me if you need any further assistance. My contact details are in the “contact page” of the blog. HAPPY CODING!!!