Deployer-script for upgrading Grav installations

So I was chatting with @OptikWebCreative and @paulhibbitts about upgrading Grav, and best practices for doing so (also requirements, ideally). I’m sure we’ve discussed Fabric at some point in the past, and I’ve used it for a complete deployment workflow from testing to staging to production.

A PHP-alternative to Fabric is Deployer, which in many ways work the same just not with Python. I mocked up a simple example of how to upgrade a number of Grav installations (see bottom of post).

All it requires is that you install Deployer (composer require deployer/deployer), define your sites (can be local or servers, they are local in the example), then execute tasks through php dep TASK. The currently defined tasks are upgrade:backup for creating a backup for each installation, upgrade:core to upgrade Grav itself, and upgrade:plugins to upgrade all plugins.

A “master”-task, upgrade, runs them all and its all based on Grav’s CLI commands. Note that user-inputs are ignored (see the -y-flag) to force upgrades to be done without asking you Yes/No for each one. Script:

/* Uses Deployer (, install instructions: 
 * Or simply `composer require deployer/deployer`.
namespace Deployer;
require 'vendor/autoload.php';

// Configuration
set('default_stage', 'production');

// Servers
	->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site1');
	->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site2');
	->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site3');
	->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site4');

task('upgrade', [
desc('Backup Grav installations');
task('upgrade:backup', function () {
	$backup = run('php bin/grav backup');
desc('Upgrade Grav Core');
task('upgrade:core', function () {
	$self_upgrade = run('php bin/gpm self-upgrade -y');
desc('Upgrade Grav Plugins');
task('upgrade:plugins', function () {
	$upgrade = run('php bin/gpm update -y');

Thanks very much for this fantastic script @olevik!

Here are some additional notes for people on shared hosting (unix) who would like to use this backup/update script:

  1. In my root directory (i.e. www), I found it helpful to create a folder called deployer to hold the above PHP script and required dependencies. I named the file containing the PHP script deploy.php.

  2. Once I verified my web host had composer installed (i.e. composer -V) and I ran the command to install Deployer, I found it useful to move the created folder ‘vendor’ into the ‘deployer’ folder.

  3. For each Grav install listed in deploy.php a full path is required. So, for example my test Grav site location looked like this: ~/public_html/ t-site/.

  4. Once in the deployer directory using Terminal, I first ran the script to perform a backup on all listed sites. To do this I entered php vendor/bin/dep upgrade:backup. You should see some feedback messages as the script runs.

Thanks again to @olevik for both the script and helping me get things going with my web host. I hope the above information helps others using this backup/update script with shared hosting.