7 ms·
Ask HN: How do you deploy your PHP apps to production?
I have several php applications for various projects and the code is deployed in production using either rsync or subversion. But I want all apps to be deployed with scripts using one method for consistency. Which methods have been successful for you?
- workhorse 16y agoGIT! 'nuff said.
- mithaler 16y agoWe have a script that tars up projects or specific files and uploads them and puts them in place, but lately we've been moving towards plain svn. If it were up to me, it'd be git, with separate branches for production and beta for easy merging.
- cm 16y agoI wrote this up when I was dealing with the same issue a few months back - a simple deploy script for PHP applications using git: http://themetricsystem.rjmetrics.com/2010/02/01/simple-deploy-script-for-php-applications/ http://themetricsystem.rjmetrics.com/2010/02/01/simple-deplo...
- sjs382 16y agoftp a tarball then untar, or rsync.
- ianl 16y agoI use git, with three levels, dev (active development), stage (current stable version), and production. All three have different branches. Then I have a bash script that configures them accordingly.
- bkorte 16y agoWe use Trunks (http://www.trunksapp.com http://www.trunksapp.com) to host our SVN repos, then have post-commit hook fire an HTTP request to the production staging server to check out the latest revision. We manually initiate an export from the live server, although we likely will look in the commit message for a keyword (like [live]) and initiate from there.
- gorm 16y agoGit or rsync
- willlangford 16y agoBeanstalk Hosted SVN/GIT has deployment tools. I haven't used them as I do my pulls manually.
- aonic 16y agobash script checks out SVN code, then uses a configuration file to build bundles of JS and CSS files using YUI-compressor, and add query string timestamps to CSS images for cache busting. After all that, the code is rsync'd to various web servers
- abyssknight 16y agoCapistrano, despite being written in Ruby, will deploy PHP. I've used it to deploy WordPress and SMF installs once or twice. The advantage here is that you don't have to choose git over svn or any CVS for that matter. You can keep your configs separate and link them in.
- zackham 16y ago+1 for Capistrano, we use it to deploy Rails, Sinatra, and PHP apps. gem install capistrano-ext and you can do easy multi-stage deploys (deploy a different branch to your staging/testing/beta server by doing cap staging deploy vs. cap production deploy for example). More details here: http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage
- agotterer 16y agoWe use capistrano with multi-stage deployment. There is a recipe called "railsless-deploy" that removes all the rails dependent processes (http://github.com/leehambley/railsless-deploy http://github.com/leehambley/railsless-deploy). We also use the "git-deployment" recipe which does auto tagging of staging and production pushes (http://github.com/apinstein/git-deployment http://github.com/apinstein/git-deployment).
- EvanK 16y agoCapistrano + Git. Works beautifully, and rolling back bad deployments is a breeze
- hlidotbe 16y agoWe use Mercurial here. Easy, secure (ssh with keys) never forget files, small transfer size, possibility of committing regularly when the client has access to the files. With hooks, the update is done as soon as the changesets are received. In some cases we can even create websites on the fly with a simple "hg clone" I guess Git allows more or less the same workflow but Mercurial is easier for your designers.
- kellishaver 16y agoYes, I do basically this, but with Git.
- mikelbring7 16y agoI started to use http://www.deployhq.com/ http://www.deployhq.com/. I was already using their http://codebasehq.com http://codebasehq.com for GIT hosting. Works great, server does not even need to have GIT installed, it can use ftp or ssh.
- JonnieCache 16y agoUpvoted, I've been checking this out recently. As a codebase customer they sent me a free account to deployHQ and it seems pretty nice. It has an API (with a rubygem) so you can integrate it into your scripts to achieve whatever level of fancyness you need. I'm also looking into the possibilities around having a 'deploy' or 'production' branch in git, and a post-commit hook that automatically deploys (with another script obviously) any commits to that branch. This is how heroku works and it's much cleaner than capistrano in my eyes.
- apowell 16y agoI deploy my CodeIgniter apps via the Springloops hosted SVN service.
- mise 16y agoSince I'm only updating one PHP app at a time, I commit my changes to the SVN repo, then SSH into the server and update.
- atstsolutions 16y agoWe have build scripts for phing, exports from subversion, migrates the database, loads stored procs, triggers and views, creates symlinks for data here and there, creates our dojo build layers, and builds a couple of executables we need. Capistrano is better for the simple stuff, but once we started doing more we moved to phing.
- dclaysmith 16y agoWe have a bash script which grabs the latest Phing config/property files and then Phing handles the rest... * calls YUI Compressor to minify css/js * calls a custom script to upload images to the CDN * calls dbdeploy to update our staging database * symlinks the "built" revision to our staging site When we push a build from staging to production, we run a small bash script that calls Phing which symlinks the desired revision to the production site.
- albahk 16y ago+1 Phing. We use Phing for deploying to production and deploying a staging instance of the app. Phing can checkout from SVN, run a mysqldump to snapshot the DB, modify text files (i.e. different .htaccess files for staging/production), run arbitrary shell commands and ping web-APIs for notification etc. Deploys take between 10 and 30 seconds.
- sammcd 16y agoI deploy a large symfony php app with capistrano. The only big change I needed to add was to tell it not to run the server restarting code, other then that it wasn't that hard. Rollback support, and the fact that I don't have to login to the server and run commands each time I deploy is great.
- rtuck 16y agoI've tried out a few different tools now; the only two I've had any real success with were Capistrano and Fabric. Capistrano works well, great git integration, but it does have some rails-isms you need to override to make it work sanely. The capistrano-php extension can help with that: http://github.com/namics/capistrano-php http://github.com/namics/capistrano-php but you'll need to use gem to manage it. You'll also definitely want the multistage plugin which doesn't come standard. There were some bugs present in the CVS integration which may be a problem depending on your source control system. I've also tried Fabric: http://docs.fabfile.org/0.9.2/ http://docs.fabfile.org/0.9.2/ I liked the tool. I found it a bit more low level then Capistrano but also a little simpler to work with. It comes prepackaged (albeit an older version) in Ubuntu without any dependencies other than stock python which our sysadmin preferred to using Ruby gems. I do recommend the new version found in pip though. The two main problems with Fabric are its lack of any integration plugins and the Paramiko SSH library it uses has no support for SSH key forwarding (there is a workaround: http://lincolnloop.com/blog/2009/sep/22/easy-fabric-deployment-part-1-gitmercurial-and-ssh/ http://lincolnloop.com/blog/2009/sep/22/easy-fabric-deployme... but it has its own set of problems). In the end, neither worked out for me. Capistrano had to much of a learning curve for my co-workers and Fabric wouldn't work with our SSH setup. For now, I'm using a script in our working directory that I SSH to, run, and it updates the code in place. Crude, but ultimately effective. That said, definitely looking forward to a replacement.
- grumpycanuck 16y agoI was using Capistrano too but, like you, couldn't get my co-workers up-and-running with it so we switched to using Phing. I didn't want to be the only one doing deployments at work.
- sandGorgon 16y agohey thanks - we were trying to figure out between cap and fabric and your answer was of big help.
- Ixiaus 16y agoI used to be a PHP developer (Python only now) but I still used Fabric extensively. Rsync is invaluable, tying it in with fabric makes for a pretty useful deployment tool.
- f1gm3nt 16y agoRight now I'm using symfony php framework that deploys the code to whatever server I want(uses rsync and you must have access to ssh on that server). All the projects are kept in svn repo's. I can imagine writing a script that just runs every so often to sync the staging server to the production server, however I don't really care for this method because I want more control. I may change my mind in the future. For some internal applications that I work on at work, we deploy them using the good ol' "svn up". I really don't like this method for a ton of reasons. The first reason being I can just goto http://www.example.com/.svn http://www.example.com/.svn and see all the svn files. I think the best by far is using rsync. Some things that I have done with rsync is configure the database settings in a config file, then just have rsync ignore that file so I can set different database settings for dev/staging servers. For personal projects I usually have them on a private space on Assembla, which one of the options is they allow you to FTP your code to a server. I haven't used it myself, but I can see where this would be useful.
- tonyarkles 16y agoYou could use a .htaccess file to prevent the .svn directory from being accessible, I would think
- koichirose 16y agoI use git with a remote repository to which you can push (and pull) stuff easily.
- ivanstojic 16y agoI do this as well, for 5 websites based on a custom PHP microframework. Git kicks ass!
- wvenable 16y agoSubversion -- the website is a working copy of the production branch and I just do an svn update when changes need to be deployed. The whole thing is wrapped up in a script that makes it possible to one-click deploy changes. The biggest thing is the application is directory independent and auto-senses the host for database selection. This means that no changes are required to the application to run it in development, staging, or production. Edit: Apache is setup so that no .svn directories are served. Given that most web applications go through a front-controller now, I'm hoping this isn't as much of a concern anymore.
- iamjpg 16y agoWe use Subversion as well. However, we use Ant scripts to do the build work. It makes updating our servers pretty straight forward.
- wvenable 16y agoMy sites are PHP so building is limited but some things do need to be built. However, my sites effectively build themselves without the need for another tool. On the first access of a resource, if the target doesn't exist it's built by the code automatically and stored in a cache. During development, the cache is disabled so you can edit and run without any intermediate build step. Things built this way include parts of the ORM and output templates.
- Keyframe 16y agoSame here, but Mercurial instead of Subversion.
- jacquesm 16y agoSame here, not as nicely automated though (still need to actually type 'svn update'). What I really like is the ability to instantly roll back to any version. Don't forget to block .svn directories in your apache config!
- wvenable 16y ago
- ulysses 16y agoWork: rdist over ssh Personal projects: rsync over ssh In both cases I use a wrapper script to make the push as simple as possible. At work I push from the dev server to prod, at home I push from my desktop to either dev or (dev and prod). In both case I use RCS for version control.
- rbpasker 16y agophpfog.com !
- kylemathews 16y agoFor Drupal, I use Aegir (http://groups.drupal.org/aegir/overview http://groups.drupal.org/aegir/overview), Git, and Make files (http://drupal.org/project/drush_make http://drupal.org/project/drush_make). Aegir let's me spin up as many copies of my project as I want for both testing + production. Git (+ github) stores all my custom development. My Make files pull together all of my custom code + drupal contributed code + any 3rd party libraries I'm using.
- unsane1 16y agoGoodness, I hope all the people using SVN to deploy are making sure that they're taking care of the .svn directories and the resulting security issues.
- JonnieCache 16y agoI assume they're `svn export`ing rather than `svn checkout`ing.
- unsane1 16y agoYet I see at least one reference to `svn update` I'm scurred.
- gregjor 16y agoRead the whole comment. It's easy to configure Apache or whatever HTTP server you're using to not serve anything in .svn directories. Duh.
- bradleyland 16y agoDon't be afraid, just configure your Apache server correctly and you'll be fine. One-liner if you're already using rewrite: RewriteRule ^(./)?.svn/ - [F,L] If you're not: <Directorymatch "^/./.svn/"> Order deny,allow Deny from all </Directorymatch>
- joeuser12 16y agoThe bigger problem is that a svn update isn't atomic, so you are going to be in an inconsistent state for a while. Capistrano with its atomic symlink switch is a much better approach although you have to watch out for caching issues and clear caches appropriately.
- syntaxritual 16y agoVlad + Github
- dangrossman 16y agoIf you use http://springloops.com/ http://springloops.com/ to host your Subversion repositories, they let you script automatic deployments upon commits to your repositories.
- DCoder 16y agoFor hosts that support git, I simply clone/pull updates from a central repos. For hosts that don't (i.e. we used to have one project running on a Windows server with nothing but Remote Desktop access and no permission to install any VCS), I use this: alias gdate=date\ +%Y.%m.%d-%H.%M.%S gitzip () { zip -ruv "$(gdate).zip" $(git diff $@ --name-only); } Invoking `gitzip $commit` produces a zip file containing all the changed files since said commit. Unzip archive to wwwroot, check for files that need to be deleted, done.