views:

1384

answers:

12

I've always just FTPed files down from sites, edited them and put them back up when creating sites, but feel it's worth learning to do things properly.

I've just commited everything to a SVN repo, and have tried sshing into the server and checking out a tagged build, as well as updating that build using switch.

All good, but it's a lot lot slower than my current process.

What's the best way to set something like this up? Most of my time is just bug fixes or small changes rather than large rewrites, so I'm frequently updating things.

+5  A: 

You don't necessarily need to use SVN to deploy the files to the server. Keep using FTP for that and just use SVN for revision history.

John Sheehan
That's a brilliant idea - I didn't think of that!
Rich Bradshaw
Thanks. Feel free to accept the answer :)
John Sheehan
Thought I'd better wait for a few more answers before accepting :)
Rich Bradshaw
No, this is a bad idea. Your deployment needs to be 1-click; with just FTP, you won't have the database backend setup.
Alex
For consulting work, this is a perfectly acceptable solution.
John Sheehan
+2  A: 

For quick updates I just run svn update from the server.

Sometimes for really really quick updates I edit the files using vim and commit them from the server.

It's not very proper, but quick and quite reliable.

edgars
+1  A: 

If you want to do this properly, you should definitely look into setting up a local SVN repository. I would also highly recommend setting up a continuous integration (CI) server such as cruise control, which would automatically run any tests against your PHP code when ever you check in to svn. Your CI server could also be used to publish your files via FTP to your host at the click of a button, once it has passed the tests.

Although this sounds like a lot of work, it really isn't and the benefits of a smooth deployment process will more than pay for itself in the long run.

Xian
+1  A: 

For my projects, I usually have a repo. On my laptop is a working copy, and the live website is a working copy. I make my changes on the local copy, using my local webserver. When everything is tested and ready to go, I commit the changes, then I ssh into the remote server and svn update.

I also keep a folder in this repository which contains sql files of any changes I've made to the database structure, labelled according to their revision number. For instance, when I commit Revision 74 and it has a couple extra columns in one of the tables, included in the commit will be dbupdates/rev74.sql. That way, after I do my svn update, all I just have to run my sql file (mysql db_name -p -u username < dbupdates/rev74.sql) and I'm good to go.

Jurassic_C
A: 

What I do at work, is use FTP to upload changes to a test server. Then when I am finished with the section of the site that I was working on, I commit the changes and update both. Sometimes, if I am working on something and I change a lot of files in different directories, I commit it and update the test server. But I don't update the production server. But I am the only programmer here, I wouldn't recommend committing possibally buggy code if there is more than one programmer.

Echo
+1  A: 

If you want to get real funky with it, you could use a build script to get the current version from SVN, then compile your PHP code, then on a successful build, automatically push the changes to your server.

This will help in debugging and may make your code run faster. Also, getting into the build habit has really improved my coding over just pushing the PHP straight to the server and debugging via Firefox.

Rob Allen
+1  A: 

The benefits of source control reveal themselves as the complexity of the project and number of developers increase. If you are working directly on a remote server, and are only making quick patches most of the time, source control might not be worth the effort to you.

Preferably, you should be working from a local working copy of the repository (meaning you should also set up a local server). Working against a remote server using SVN as the only means to update it would slow you down quite considerably. Having said that, working with SVN (or any other source control) will yield many benefits in the long run - you have a complete history of changes, you can always be sure the server is up-to-date (if you ran update) and if you add more developers to the project you can avoid costly source overwrites from each other.

Eran Galperin
A: 

I use ZendStudio for Eclipse (currently version 6.1). And I use SVN to keep my source codes available. Initially I thought the process was somewhat slow due to commit process (and entering commit comment) and wait until it stops.

However after learning that Ctrl+Alt+C to Commit and check 'Always run in Background', the process doesn't slow at all.

Plus, I do run everything locally, then only SSH after a while.

uuɐɯǝʃǝs
+1  A: 

You should look at installing rsync to upload changes to your server.

Rsync is great because it compares your local copy of the repo to the copy that's currently on the server and then only sends files that have changed.

This saves you having to remember every file that you changed and selecting them manually to FTP, or having to upload your whole local copy to the server again (and leaving FTP to do the comparisons).

Rsync also lets you exclude files/folder (i.e. .svn/ folders) when syncing between your servers.

Shane
A: 

I did a post-commit hook to automatically update my web. It´s fast but you can make mistakes.

polyphony
+2  A: 

I'd recommend you keep using Subversion to track all changes, even bug fixes. When you wish to deploy to your production server, you should use SSH and call svn update. This process can be automated using Capistrano, meaning that you can sit at your local box and call cap deploy -- Capistrano will SSH into your server and perform the Subversion update. Saves a lot of tedious manual labor.

Daniel Schierbeck
A: 

IF on a *nix server AND you have the appropriate SSH access AND you have space to keep multiple copies of the website, THEN the single most useful versioning technique I have found is to use a symbolic link to point to the "current" version of the website. (You can still use SVN to version source code -- this is a way to easily/instantly switch between versions of the website on the server.)

  1. Set up the webserver to point to /whatever.com as the root of the website.

  2. Have a folder like /website/r1v00 to which you FTP the website files, then create a symlink called "whatever.com" that points to /website/r1v00

  3. When you have an updated version of the website, create another folder called /website/r1v001, FTP all the files for the updated site, then change the symlink for "whatever.com" to now point to /website/r1v01. If there are any problems with the new site, you can back it out instantly by simply pointing the "whatever.com" symlink back to /website/r1v00

Of course, you can/should set up scripts to automate the creation and switching of the symlink. In my case, I have an "admin" page written in PHP that lists all the available versions, and allows me to switch to any of them. This technique has saved my bacon several times...!

Obviously this does not address any issues with versioning database schemas or database content.

This is not an elegant solution, its all brute force =/
codeninja