Scripted Upgrades

Or: Upgrading multiple Grav-installations at once.

This is a guide to make upgrading multiple Grav-installations easier, using Deployer. By multiple I mean separate installations, not a multisite-installation. We'll use the path to each installation to run Grav's CLI commands, but without having to type each of them manually.

A benefit of a task-runner like Deployer is that as it runs through its tasks, it will let you know exactly what it is doing along the way. It will also show you any output from the server from the commands being run. For example, this is an output from Deployer:

And as simple as that, Deployer told Grav to upgrade all packages, which upgraded the Email-plugin to its newest version.

Prerequisites

Like with Grav, you need PHP v5.6.* or above. This also applies for the command line (CLI), so if you have multiple versions installed use the one which refers to the right version. Use the command php -v to check your default version, mine is PHP 5.4.45.

On shared environments, check with your host which command to use for CLI. In my case, this is php56 which with -v returns PHP 5.6.28. This also means prepending every path like this: php56 vendor/bin/dep list.

Some hosts also allow you to select your default PHP version to use for CLI, check with your host how to do this.

Setup

In your servers public root (like public_html or www), create a folder named deployer and enter it. We'll use this as a basis for the project. You'll want to password-protect this directory (see DigitalOcean Guide for a manual approach, or use CPanel if available).

You need to have a working installation of Grav, as well as Composer. Some hosts have Composer installed already, which you can check by running composer -v. If it is not installed you can install it through SSH -- from the root directory -- with the following:

Configuration

Because Deployer needs an explicit staging-environment, we set it to production. Further, to allow for specific php version we set a default executable to be used. This can be a named executable or the path to a specific version of PHP. Our configuration now looks like this:

If your default PHP CLI version is 5.6* or higher, you change this to set(php, 'php');.

Servers

We can set up as many servers/sites as needed, the script will be ran for each of them in order. They can be local installations or on external servers, but since this is a local setup we use localServer (see Deployer/servers for more configurations). Here's an example with multiple sites:

Note that we use absolute paths to the installations, but they are relative to how the path is interpreted by SSH. This means that on the server, we want the full path because Deployer interprets this correctly, but we could also use the tilde-key if a HOMEDIR is set, like this: ~/public_html/deployer/grav1.

Tasks

Three tasks are currently set up: backup, core, and packages. Running php vendor/bin/dep backup creates a backup of each installation, available in deploy_path/backup/BACKUP.zip, where deploy_path is the paths you configured for the servers.

Running php vendor/bin/dep core upgrades Grav itself, and does this with the --all-yes option to skip all Yes/No questions asked. The same applies when running php vendor/bin/dep packages, which upgrades all plugins and themes.

Conclusion

We can now upgrade all your defined sites easily by running the tasks in order. First we enter the public_html/deployer/-folder, and then we run each command as needed: