views:

390

answers:

5

In the past, I've always edited all my sites live; wasn't too concerned about my 2 visitors seeing an error message.

However, there may come a day when I get more than 2 visitors. What would be the best approach to testing my changes and then making all the changes go live simultaneously?

Should I copy and paste ever single file into a sub-folder and edit these, then copy them back when I'm done? What if I have full URLs in my code (they'll break if I move them)? Maybe I can use some .htaccess hackery to get around this? What about database dummy test data? Should I dupe all my MySQL tables and reference those instead?

I'm using CakePHP for the particular project I'm concerned about, but I'm curious to know what approaches people are taking both with Cake (which may have tools to assist with this?), and without a framework.


I've been getting a lot of recommendations for SVN, which sounds great, but unfortunately my host doesn't support it :\

+17  A: 

The best thing you can do is to create a staging environment in which you test your changes. The staging environment (ideally) is a complete, working duplicate of your production system. This will prevent you from experiencing many headaches and inadvertent production crashes.

If you are working on a small project the best thing to do is to recreate your remote site locally (including the database). Code all your changes there and then, once you are satisfied that you are finished, deploy the changes to your remote site in one go.

Andrew Hare
I'll second that. It's proven to be immensely valuable especially when working with clients and being able to show them a change before it goes live.
jerebear
Also, it may seem like a hassle to duplicate and copy everytime but it's far worse to put a screw up out there for your visitors to see it.
jerebear
It's less of a hassle if you use version control software, so the deployment process is just committing your proven working code and updating it from the repository on the live instance.
chaos
I cant believe that peopel still upload theire scripts without testing before in a local-copy of the online server :)
DaNieL
DaNieL -- we're lazy. It's just a heck of a lot easier than trying to dupe your server. Not all of us are running LAMP at home.
Mark
+3  A: 

I set up a development server on my laptop that duplicates my web server as closely as possible (server software and configuration, operating system, filesystem layout, installed software, etc.) That way I can write the code on my laptop and test it locally; once I've gotten things working there, I copy it to the server. Sometimes a few problems arise because of slight differences between the two computers, but those are always quickly resolved (and just in case they're not, I have my site in an SVN repository so I can always revert it).

On another website I used to maintain, I used a slightly different tactic: I designated a URL path within the site that would be a development version of the base site. That is, http://www.example.com/devweb would ordinarily mirror http://www.example.com, http://www.example.com/devweb/foo/bar.php would mirror http://www.example.com/foo/bar.php, etc. I created a folder devweb under the document root, but instead of copying all the files, I configured the server so that if a requested file didn't exist in the /devweb directory, it would look for it under the document root. That was a more fragile setup than having a separate development server, though.

David Zaslavsky
Why was it more fragile? That sounds like a clever solution. Would be much easier to set up than trying to duplicate my server.
Mark
Basically it took a little trickery to get PHP to read a separate configuration file for the development site and merge it with the live site's configuration file; plus we were limited to using relative URLs for images, stylesheets, intrasite links, etc.
David Zaslavsky
+5  A: 

I would recommend putting your website code under full version control (git or subversion). Test and maintain your source in a separate, private sandbox server, and just check out the latest stable version at the production site whenever it's ready for release.

For database support, even for small projects I maintain separate development and production databases. You can version the SQL used to generate and maintain your schema and testing or bootstrapping data along with the rest of your site. Manage the database environment used by your site from an easily separated configuration file, and tell your version control solution to ignore it.

Absolute URLs are going to be a problem. If you can't avoid them, you could always store the hostname in the same configuration file and read it as needed... except within stylesheets and Javascript resources, of course. My second choice for that problem would be URL-rewriting magic or its equivalent in the development server, and my last choice would be just messing with the /etc/hosts file when I wanted to test features that depend on them.

Ash Wilson
+1. Using some sort of versioning system saves so much time migrating changes from dev to production.
Adam Backstrom
+2  A: 

I have a number of websites written in CakePHP. I develop and test on my local machine, using the database on my production server (I just have a MySQL login that works for my static IP address).

All code is checked into Subversion, and I then have a continuous integration server - Hudson:

https://hudson.dev.java.net/

This builds and deploys my project on the production machine. It just checks out the code in subversion for a specific project then runs a simple script to SSH/copy the files into the staging or production location on the server. You can either set this up to be a manual process (which I have currently) or you can set this up so that it deploys once code has been checked in. There's lots of other CI tools that can be setup to do this (have a look at Xinc as well).

http://code.google.com/p/xinc/

As for absolute URLs you can always setup something in your host file to resolve the site locally on your machine instead. It works for me, just don't forget to take it out afterwards : )

Hope that helps...

Jon
+2  A: 

I have a version of config/database.php that uses the php server variable "SERVER NAME" to determine which system the app is running on. Then when I clone my git repo across my home system, development site (which shares the same specs as the live machine), and the live machine they all connect to their respective databases.

I pasted here, but I also believe its available on thebakery.

http://pastebin.com/f1a701145

modethirteen
Oh! That's a pretty clever solution. Thanks for sharing :)
Mark