Do you have trouble implementing a phase II of a website? I know it can be a pain having to develop a phase II on top of an existing live site. Obviously you can’t just modify the live server without testing; but other alternatives can be troublesome as well.

Its not fun having 2-3 different copies of a website. Get’s confusing which is live, what changes have been done on which, etc. Well I found one way to somewhat ease the pain. I know some of you out there have more in depth solutions such as ZooKeeper or Capistrano, but both didn’t really suit my needs and are a bit complex.
My solution would be to have two folders in the public_html of your website. Have one named “staging” and the other named “production”.
/public_html
/staging
/production
Each folder would be a “copy” of your site, and each would have its own db. I would suggest you name your db’s yoursite_staging, and yoursite_production respectively.
The only real requirement for this is that must have a unix server as that is the only server that supports .htaccess. You also have the mod_rewrite module installed.
Once you are sure the requirements are met, put the following in your .htaccess:
# enable module_rewrite
RewriteEngine On
# make sure the host is what you expect, and don't rewrite subdomains
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
# make sure they aren't requesting the actual production directory. Otherwise it would be a continuous loop.
RewriteCond %{REQUEST_URI} !^/production/
# rewrite any request file to the production directory
RewriteRule ^(.*)$ /production/$1
The following are some examples of how the above will redirect:
/index.php => /production/index.php /css/styles.css?v=1 => /production/css/styles.css?v=1 /images/gallery/myimage.jpg => /production/images/gallery/myimage.jpg
Now if you ever need to change the folder that is shown live on your site, just change any line that has “production” in it. Alternatively you could just rename the “production” folder to “staging” and vice versa.
What do you think of this concept? Is it too simple? If you got a better way to do something like this please sure it in the comments!
Thanks very much for the information! It does seem simple, but sometimes simple is better in web design.
Twitter
Follow me on Twitter to keep up to date!
RSS Feed
Keep up with all of our updates by subscribing to our RSS feed!
FaceBook
Join our group on Facebook and become a fan of us!