Deployment automation

This is one of those things that I know all the experiences web developers do but I haven’t taken the time to figure it out yet. I think it’s time.

What techniques do you guys use for deploying (or updating) your applications to external web hosts?

This is what I have always done, which pretty much sucks:

  1. SVN Commit via TortoiseSVN (~6 seconds of clicking around)

  2. SVN Export via TortoiseSVN (~15 seconds of clicking around)

  3. Open FileZilla (3 seconds)

  4. Upload exported files, with "Export if source newer" option (10 seconds)

This all adds up to a half a minute. Sometimes I do this 10 times a day. I hate doing it. I don’t even take the site down usually when performing the update. Not good

It seems I could create a script to automate all of this, so all I have to do is run it and bam the site updates to my local copy.

I am looking for advice for the best way to set this up. I’ve done some googling and it seems there are a whole bunch of options, so many I don’t know where to start.

What I would like:

  1. Only changed or new files should be uploaded to the server, that are under version control. No need to re-upload the whole thing each time

  2. Scripts to take down and up the site to run before doing maintenance (could be as simple as uploading an alternate index.php file).

What I think I need:

  1. FTP software that can be run from command line (what is good?)

  2. Figure out how to use version control from command line

What methods have you guys gone about? Any examples out there? It seems the script could be written in pretty much any language including php.

I am using windows. It seems that most examples on the web are directed towards linux which I really don’t know much about.

I’m going to play around but I was wondering if anyone had any starting advice before I try something out which turns out to be a bad method

Thanks,

Jonah

We are using "svn update" to deploy. It usually happens that you may find bugs or add new features after the system is deployed for the first time. Then you will appreciate how convenient "svn update" is. To make it safer, you could use svn branches to make sure you only "svn update" on the production server when you think the code is stable enough.

Ah yes this solution did cross my mind. Is this possible on a shared host however?

Just did some googling and it seems to get it working I first need to learn how to connect to the server with SSH. So it is possible. So I’m going to do some playing around with that. You pointed me in the right direction. Thanks!

EDIT: just got putty/ssh working on dreamhost. This is cool stuff… svn is already installed

EDIT2: OK it seems like its gonna work on my other host too. This is gonna save a lot of time

We’re using Git for versioning, since we have all our servers mounted as remoted drives (through ssh/sftp)

we just copy the files over. To make sure noone is really browsing your site during that time you update the site,

just replace your index.php with a temporary one telling the user you are updating the sitechanges, then replace

your index.php with the new/old one.

That way you can make sure no user makes any database calls or other updates on your site that potentionally could

mess something up.

To update the database (MySQL) we usually use the synchronization tool in MySQL Workbench, if there’s nothing that

potentionally could mess up data we just push the changes otherwise we would have to make some script to convert the

data/temporarily move it or whatever suits the changes. :)

I really recommend MySQL Workbench if you are not using it already, got all those nifty tools builtin and it’s all free.

Also make sure to use the Beta version, the older ones are not as good.

Just one thing i came to think of when you said you use SVN, doesn’t that mean you also have tons of .svn folders

in your production server that might actually expose PHP code to the user if you don’t make sure to block users

from accessing them? Just a heads up to Jonah if you didn’t think of it already :)

I’ve never heard of mounting a server as a remote drive… just googled it and it sounds pretty nifty/cool. I like using svn update as apposed to copying the files over as it takes less time for the server to do, as it only sends the file changes.

I just checked if the .svn folders were accessible and luckily they are not (for whatever reason).

I use plink (command line version of putty) to deploy the application via a .bat file (one click!). I am also planing on creating .bat files to bring up and down the server for public use (by replacing index.php probably).

I hear git has a lot of improvements over svn so I hope to learn it someday when I have time…

For updating the database, I have always just done it manually on the server phpMyAdmin script. Not the cleanest method… Whenever I made a change on my local database for testing, I would just jot down the sql that phpMyAdmin executed, then executed the same thing on the remote server phpMyAdmin once deploying. Haven’t needed to convert any data yet. So I’m going to try out this MySQL Workbench and see what it’s about…

I know, that everyone is knowing it, but i want to mention rsync for every non-svn/git/googlecode project around. Initial sync takes long (since it copies up ALL data) but after that, only the changes are ‘commited’ which makes it very fast ( way < 1 second )…

to jonah

Look at SQLyog (Webyog Softworks). 2 Powertools there: DataBase Synchronization Wizard and Schema Synchronization Tool.

The beta of MySQL workbench seems to have a lot of bugs right now. For instance, after altering a table, the changes don’t show until I refresh my object explorer, and when I do that, I have to re-navigate to where I was. Besides the bugs it’s perty good tho

gonna take a look at SQLyog

On all of my past projects I simply uploaded new/updated files via FTP without putting site offline or something. It worked well since the overall amount of files were always small. I’m looking forward to use a version control system to do the updates of new projects.

You guys know if there’s an offline svn/git/bazaar solution (maybe a bundle with webserver or something)? Because for now I work alone but I would still like to use versioning and then later put everything online so others can access.

Well that’s the good thing about Git, it is local, you can do as many commits you wish locally before you push it to your server (if you do push it to a server).

Git is very similar to SVN in usage, it took me about 5min to learn how to use it, really :)

It’s even simpler if you use a GUI tool for it aswell. I however prefer my terminal if i dont want to check code diffs that is.