 |
Sunday, 5 September, 2:16 AM
|
|
Advertisement:
|
Adding subdomain.localhost when developing
When I was developing the new look for this site I wanted to change several sections of the site from folders to subdomains. Developing locally is much simpler than constantly uploading and checking your work online so I knew I would have to find a better way of developing locally with subdomains than to pretend that the localhost/folder/ was actually folder.localhost. After many hours of finding bits and bobs in various articles hidden away I managed to piece it all together and get it working. Here I share the steps.
|
Before you take any of the following steps be sure to backup all the files you are about to edit. No responsibility whatsoever is taken for problems arising from you following my instructions. These steps worked for me but I am not garenteeing that they will work for you.
At the time of writing this article I ran
Windows XP Pro
Apache 1.3.28
php 4.3.3
To add subdomain.localhost to your local development arsenal you need to take the following steps:
1) Edit your httpd.conf file to say the following:
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot C:serverApachehtdocssite
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>
<VirtualHost 127.0.0.2>
ServerName subdomain.localhost
DocumentRoot C:serverApachehtdocssitesubdomain
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>
Obviously you can change the subdomain name to anything you like.
IF you are an expert then you can also change localhost, and if you have several sites running the numbers do not have to be 127.0.0.1/2 as when you follow the next step you can add any IP you like.
Save and exit the httpd.conf file.
2) Edit C:windowssystem32driversetchosts
This file appears on the drive you run windows on. It may be in c:WINXP.... Be sure to use a plain text editor as you don't want to add any text formatting by mistake. Add the line
127.0.0.2 subdomain subdomain.localhost
after the
127.0.0.1 localhost
line.
If you are using several sites then they should all be listed in this file, allowing you to access them just using your servernames that you have set for them in httpd.conf. In my case I edited the file and added the following:
127.0.0.13 harrybailey
127.0.0.14 opinion opinion.harrybailey
Save and exit hosts.
Restart apache. Go to subdomain.localhost in your chosen browser.
At this point you should be seeing the index page of your localhost/subdomain folder. If not then go back and check the instructions to make sure you haven't made any mistakes.
Good luck.
|
|
|
© harrybailey.co.uk - All Rights Reserved
|