Capistrano website deployment with PHP Composer

Composer is great for handling PHP dependencies, and Capistrano is great for automated deployment, so wouldn’t it be great if you could use them together?

To do this, all you need to do is update your recipe with the following task, then add a hook to make it run when the recipe is used.

To add the hook, make sure that Composer is triggered after finalize_update (which means it will happen before symlink)

after "deploy:finalize_update", "deploy:composer_install"

Then for the task, the simplest solution is to call Composer from the CLI using the Ruby run command.

task :composer_install do
    run "php /var/www/composer.phar install --working-dir #{latest_release}"

This assumes that you have a composer.phar located outside of your repository; you can add it into your repository if you cannot place it anywhere else on the server.

If you need to download composer there are official instructions, or if you are having issues there is troubleshooting information available also.

1 comment