Laravel Post Deployment Command

Published 21st May 2014

Laravel is an amazing PHP framework, and its what I’ve used to build Artisan. Often after I’ve deployed changes to the app there are several commands I need to run on the command line such as:

php artisan down composer update php artisan migrate php artisan up

This means logging on to the remote server, finding the right direcotry and manually running each of these commands. After a while this get’s a bit tiresome and could become a big issue if you forget to do it. So I came up with a custom Laravel command that can be run after a deploy.

Put the above code in app/commands/PostDeploy.php (although it can go anywhere) and then register the command by adding the following line to app/start/artisan.php:

Artisan::add(new PostDeploy);

This reduces the above four commands (and any others you might want to add) into a single command:

php artisan post-deploy

It even supports passing an environment to the migrate command:

php artisan post-deploy --env=production

The best part is that I can get Beanstalk to trigger this command automatically after a deploy so that I don’t even need to do anything (excpet maybe check that the deployment ran ok). Awesome sauce.