So I’ve just reinstalled my PC at home and had to go through the rigmarole of setting up my PHP stack (PHP, Apache and MYSQL) on windows. Now first of all I’d like to say that although i currently have a windows desktop at home my prefered development operating system is mac os. On most operating systems this is quite easy, your either treated to pre installed version of the software the packages or the use of a nice easy to use package manager. On windows we don’t have such luxuries so we have to find and install the packages our self.
First of all we need to install Apache httpd which can be downloaded from http://httpd.apache.org.
Installation of apache is quite a simple process and by excepting all the defaults allows you to get the web server up and running in no time.
Once the installation is complete we need to make a few changes to the config changes in order to set up vhosts. On windows 7 and vista we need to edit the config file as the administrator, this requires us to find the executable for your favorite text editor (mine is gvim on windows) right click it and press launch as administrator.
Open the apache config file located by default at
C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf.
Locate and uncomment (remove the #) the line #Include conf/extra/httpd-vhosts.conf.
We now need to allow access to out sites directory by adding:
<Directory "C:/path/to/Sites">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
The last thing we need to do in this file with regards to setting up vhosts is add the line:
Include "C:/path/to/vhosts/*.conf"
Now we can add files such as “C:\path\to\vhosts\example.conf” with the content:
e now need to allow access to out sites directory by adding:
<VirtualHost *:80>
DirectoryIndex index.php
DocumentRoot "C:/path/to/Sites/example/public"
ServerName example.localhost
ErrorLog "C:/path/to/logs/example-error.log"
</VirtualHost>
At this point we should now be able to restart apache by right clicking on the icon in the system tray and clicking restart, If every thing is set up correctly apache should come back up and you shouldn’t see the icon go red.
Apache is now set up to serve vhosts by we need to tell our system that the addresses were using for the vhost (example.localhost in this case) can be accessed by the system. The easiest way to achive this is to modify the systems hosts file. This is the file that windows will check before attempting any dns lookup, it is located at “C:\windows\system32\drivers\etc\hosts” and needs to be edited as an administrator.
Add the line:
127.0.0.1 example.localhost
Only this left to do now is open up our web browser and try visiting example.localhost, if all is well we should see our example site. Good luck