I am currently using Windows 7 and I have XAMPP installed in the default folder so things might be different on your machine just Google them for your OS. Now lets get underway.
By default XAMPP sets up all the sites you create to have
http://localhost as its top-level domain, and giving your site
http://localhost/site as the url unless you install your site in the top-level folder. But what happens when you have multiple sites or you want to test out environments which would require you to have different domains, well I am going to teach you to do just that.
- You need to have XAMPP installed ( 😐 )
- Open up the Xampp control panel and stop Apache (Ensure that you don’t have it running as a service … this is where doing so complicates things)
- Navigate to
C:/xampp/apache/conf/extraor wherever you installed xampp
- Fire up your text editor with administrative privileges and open up
httpd-vhosts.conffound in the
- At the very bottom of the file paste the following
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs" ServerName localhost </VirtualHost>
With out that line of code you will lose access to your default
htdocs directory. IE.
http://localhost/ will be inaccessible.
- Now copy and paste the code below .. below the first code
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/testsite" ServerName testsite.dev ServerAlias www.testsite.dev <Directory "c:/xampp/htdocs/testsite"> Order allow,deny Allow from all </Directory> </VirtualHost>
For Persons using the latest version of Apache (at time of this update 2.4 +) use the code below as the above code is for Apache versions below 2.4
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/testsite" ServerName testsite.dev ServerAlias www.testsite.dev <Directory "c:/xampp/htdocs/testsite"> AllowOverride All Require all Granted </Directory> </VirtualHost>
#Change everywhere you see test site to the location of your site and the domain name you would like to use, the most common ones are .dev, .loc and .local (I believe anything except the traditional .com / .net domains would work fine … but don’t quote me on it)
- Now we head over to our Windows Hosts File, to edit the HOSTS. the file will be located at
C:/Windows/System32/drivers/etc/hosts, where hosts is the file.
look for the line above, and enter your site mimicking the layout
127.0.0.1 localhost 127.0.0.1 www.somesite.dev 127.0.0.1 www.multisite.dev 127.0.0.1 demo.multisite.dev 127.0.0.1 www.testsite.dev #change this to the domain name you chose earlier
change it to reflect the lines above (if you have problems saving it meant you didn’t have your text editor running in admin mode.
- Restart Apache and test to make sure it is working
If you have any problems comment if not … give it a like