If you develop multiple websites, you may need to create localhost subdomains, so that you can access them in your web browser using a similar uri: http://site1.localhost where ‘site1′ is anything you want.
Creating localhost subdomains is a two-step process:
- you must declare your subdomain in HOSTS file.
This step is very important, otherwise if you don’t do it, your browser will search the web (and not your local computer) to find your website and you won’t get anything.
Under windows, HOSTS file is there:
Windows XP : C:\WINDOWS\SYSTEM32\DRIVERS\ETC
Windows 2K : C:\WINNT\SYSTEM32\DRIVERS\ETC
Windows 98/ME : C:\WINDOWS
Under linux, it is: /etc/hosts
Open the file, and append a new line with the following:
replace ‘site1′ with wathever you want
- Next step is to edit apache httpd.conf file and declare your subdomain.
[UPDATE: if you use xampp on windows, you may rather edit /apache/conf/extra/httpd-vhosts.conf]
Locate your httpd.conf file and append the following:
<VirtualHost *> ServerName site1.localhost DocumentRoot "path/to/website" </VirtualHost>
Don’t forget to replace ‘site1.localhost’ with the local subdomain name you want to use and “path/to/website” to the path of your website (ex: /var/www/site1).
- it’s important to wrap path into double quotes in case a folder name contains a space
- it’s important NOT to add trailing slash/backslash as it will make apache not work!
Restart Apache, open your browser on http://site1.localhost and your website should be loaded