Skip to content

Instantly share code, notes, and snippets.

@debojyoti
Last active February 21, 2018 15:20
Show Gist options
  • Save debojyoti/84f2cff0ba83d5b1f7c77ae81277f1a2 to your computer and use it in GitHub Desktop.
Save debojyoti/84f2cff0ba83d5b1f7c77ae81277f1a2 to your computer and use it in GitHub Desktop.

Create or add virtual hosts on apache in windows

For first time - follow all the steps and ignore step-2 from next time

1) (File-1 : hosts)

Open the following file in Notepad (Run as Administrator)

C:\WINDOWS\system32\drivers\etc\hosts

Look for the following line at the bottom:

127.0.0.1 localhost

Add new localhost domain on a separate line of that file

127.0.0.2 newsite

(File-2 : httd.conf)

2) Open the main Apache configuration file, httpd.conf (For first time)

For xampp users,location

C:\xampp\apache\conf\httpd.conf

Comment out the Include... line after Virtual hosts

#Virtual hosts
Include conf/extra/httpd-vhosts.conf

3) (File-3 : httpd-vhosts.conf)

Open extra\httpd-vhosts.conf

For xampp users,location :

C:\xampp\apache\conf\extra\httpd-vhosts.conf

i . Remove the hash mark from the beginning of the line

NameVirtualHost *.80

ii . Add virtual host block in that file (at the end)
<VirtualHost *:80>
	  DocumentRoot "C:\xampp\htdocs"
	  ServerName localhost
</VirtualHost>

<VirtualHost *:80>
	  DocumentRoot "C:\xampp\htdocs\newsite"
	  ServerName newsite
</VirtualHost>

Restart apache!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment