Skip to main content

By Steven Grant

Deploying Statamic with

We recently had a Statamic project that needed to make use of to enable zero-downtime deployments.

If you don't know, Statamic is a great flat-file CMS, not a static site generator (at least not yet) that allows your content (and everything else) to be versioned controlled.

Whenever a client makes changes to their content, those content files become Markdown files on the server and you need a way to get those changes back into Git.

The problem with using Envoyer, compared to Laravel Forge, is that it doesn't deploy a cloned Git repo. Instead, it just deploys the files into a release.

Solving the problem

There's 2 ways you can work with Envoyer and each will really depend on your team/client workflow.

Solution 1

As an example, Asana has their content editors use Github as their control panel for Statamic. This means they could (and probably should) disable the control panel for their Statamic production environment.

Using the Asana example would totally allow for you to then deploy what you have using Envoyer.

Solution 2

Our solution to our client's workflow was to create a secondary environment (Yay for 1Password string generation 😂).

This secondary environment is a small Digital Ocean server provisioned via Laravel Forge which then deploys a branch called cms. This becomes the CMS environment that content editors use.

You can, of course, use Laravel Forge to create firewall rules limiting access by IP. Or, if it needs to be publicly accessible (you also don't want Google crawling it) use this snippet inside index.php

if($_SERVER['SERVER_ADDR'] == '') {

  $username = 'username';
  $password = 'password';

  if (!(isset($_SERVER['PHP_AUTH_USER']) && ($_SERVER['PHP_AUTH_USER']==$username && $_SERVER['PHP_AUTH_PW']==$password)))  {
        header('WWW-Authenticate: Basic realm="This site is protected"');
        header('HTTP/1.0 401 Unauthorized');
        // Fallback message when the user presses cancel / escape
        echo 'Access denied';

This is a great piece of code that protects an environment from prying eyes. However, make sure you change the SERVER_ADDR to match the public IP for your server.

Next, we turn to Spock.

Vm Rnmdf3V Ukf N8 Ks7Mh B3 Nucr44 Hx P1Yt Vi Hgezc

Spock is a nifty first-party (the Statamic team made it) utility for Statamic.

With Statamic built on Laravel, it listens for a series of different events within the Statamic app - page saves, form submissions and such - and with each event, Spock commits that change to Git, along with the user name, giving you an instant audit trail 🙌🏼.

P Va3I Lwhz Hyx14 Uat90Bd5 Stw Lowd Brt O2 Ssx Wgh

Then we have an environment variable GIT_PUSH=true set to push those changes back to Github.

From there you can manually merge those changes into master and then deploy with Envoyer 😎.

Want to read more tips and insights on working with a Statamic development team that wants to help your organization grow for good? Sign up for our bimonthly newsletter.

By Steven Grant