Replicate Server Environment At Home On Windows

This article shows a few tips and tricks on how to set up a server environment on Windows that, as much as possible, replicates your hosted server environment - be it Unix, Linux or whatever. You should have a reasonable understanding of Apache and PHP and MySQL should be installed already. For more details on this, please check out the related links section of this site.

The development stage of the web site building process is very important. It makes life a whole lot easier if you can replicate environments so the switch between development / testing to production is as seamless as possible. This guide shows how I go about the process of setting up a similar staging area for my site before pushing to production. Although nothing major can happen if you follow the steps provided it is always recommended to take back-ups before proceeding.

Server (Apache), PHP, MySQL

To make environments are close to each other as possible, you should try to download the same, or similar, versions of the software that is currently running on your hosted server. This article does not cover the installation of Apache, MySQL or PHP. However there are a couple of tweaks to Apache's httpd.conf file and potentially PHP's php.ini file respectively. Unless you are considering changing the port of MySQL no real changes are required.

Scenario

You have just bought a shiny new domain name, greatsite.com and you have paid for hosting as very affordable and reliable web hosting company. You have set up the DNS to point to the IP address of your host and are ready to create a development environment at home on your windows box.

The first steps should be to check out what your paths are to your root or web directory and to any other relevant facilities, such as send mail, ftp or cgi bin and anything else that you may perceive to be appropriate. Only the former check is mad in this example - as is my need to set up the server environment to fit my needs.

Replicate Directory Structure

Vivid usually have a set up that your public_html directory is located as: /home/site_name/public_html or replace public_html with www to take into account the symbolic link. So for greatsite.com the root directory is /home/greatsite/public_html.

I have plenty of hard-drive space, so it is very easy for me to create a directory at the same level. X:\home\greatsite\public_html. Once you have created that, create a basic index.html or index.php so that when you finally navigate to this site, there will be something to see. Open up the file you have just created with a text editor, for now, and insert some text. Save the document.

Create a Virtual Host and Domain Name on your PC

To make things easy, IMHO, I like to create a domain name similar to the real domain for my PC environment. In this example, I will create a domain called greatsite.pc - there are 2 steps to follow here and it doesn't really matter which order in which they are executed - you will still need to restart your server anyway for everything to come into effect.

httpd.conf - Virtual Hosts

To create a virtual host, see the steps taken in the virtual hosts article written earlier on this web site. If you don't want to follow this path, or you have no virtual hosts already set up, the code that you need to insert into your httpd.conf file is as follows:

NameVirtualHost *
# (1) No subdomain: http­://greatsite.pc
<VirtualHost *>
ServerAdmin webmaster­@greatsite.pc
DocumentRoot "X:/home/greatsite/public_html"
ServerName greatsite.pc
ServerAlias greatsite.pc
</VirtualHost>
# (2) Catch www: http­://www.greatsite.pc
<VirtualHost *>
ServerAdmin webmaster­@greatsite.pc
DocumentRoot "X:/home/greatsite/public_html"
ServerName www­.greatsite.pc
ServerAlias www­.greatsite.pc
</VirtualHost>

If you have edited your httpd.conf, save it but do not close the file. We will need to make a couple more changes before we are finished. If you have just edited a host include file, save and close. A couple more changes to httpd.conf are needed but virtual hosts is complete.

HOSTS

As detailed in the article linked previously, you then need to open up your HOSTS file, usually found in the following directory: %SystemRoot%\system32\drivers\etc. Use Wordpad or notepad and add the following to your file....

# PC (NETWORK, CHANGE IP TO MATCH NETWORK IP)
192.168.1.2 greatsite.pc
192.168.1.2 www­.greatsite.pc
# PC (LOCAL)
127.0.0.1 greatsite.pc
127.0.0.1 www­.greatsite.pc

Save and close and return to your httpd.conf file. We are going to take a couple

httpd.conf - AccessFileName

Due to the fact that you may want domain specific features within your .htaccess file, such as rewrite rules and that trying to save / open files with no name, eg: .htaccess is just an extension, nothing before the dot, I decided many years ago to change the AccessFileName setting on my local machine so I could easily differentiate between development and production environments. Search your httpd.conf file for AccessFileName.

Find AccessFileName .htaccess and replace with:

#AccessFileName .htaccess
AccessFileName htaccess.txt

Final step is to lock-down the server. By this, I mean protect this file from prying eyes. Slightly further down the file there is the following:

<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

Change this to:

#<Files ~ "^\.ht">
<Files ~ "^(\.ht|htaccess.txt|htpassword.txt|Thumbs.db|Desktop.ini)">
Order allow,deny
Deny from all
</Files>

Note that the original conditions have just been commented out (#) so you can easily undo any damage that may have been done. Save the file then restart your web server.

That's it. Type in http://­greatsite.pc into the address bar of your favorite browser and you should see the page you created in the first few steps of this guide. Have fun.

Syndicate content