Deploy Statamic with Git and rsync

Learn here our recommended way to deploy Statamic with Git and rsync on fortrabbit. You'll deploy to fortrabbit using Git (and Composer) and (optionally) synchronize contents with rsync.

# Get ready

You should have Statamic running on your local machine, have a good understanding of Git and rsync, have an App on fortrabbit ready. Read our Statamic intro first.

# Configure Statamic for Git with rsync

Open your local Statamic project folder with your text editor or IDE. Within it open the .gitignore file at the root level to tell Git to ignore all content. We need to add any folders to .gitignore which contain user-generated content:

# Exclude stuff you are creating from Git
/content
/users
/resources/blueprints
/resources/fieldsets
/resources/forms
/resources/users
/storage/forms
/public/assets
shell

PLEASE NOTE: This is our recommended way of doing it. It separates code from content. You will need to run dedicated rsync commands to deploy and update this user-generated content (see below). You can also decide to not touch the .gitignore file so that you can deploy everything with Git all together. Keep in mind that you can not pull in new contents from the fortrabbit App this way (see on work-flows above).

At that point you should be able to run the project in your local development environment already. We highly recommend developing the site locally, using fortrabbit for staging and production.

# Deploy Statamic with Git

In case you haven't already, set up Git, configure a Git repo as a remote and push the code. See our deployment intro article for more details on Git here on fortrabbit.

# Synchronize content with rsync

As mentioned above, deployment of your code base (templates and configuration) and dependencies (Statamic and Composer) is done via Git deployment. Deploying the content is a separate step. We recommend using rsync to up- or down-load new contents to and from your remote fortrabbit App (see also our rsync article). On your local computer in the terminal in the Statamic project folder execute:

# SYNC UP: from local to remote
$ rsync -avR ./content ./users ./resources/blueprints ./resources/fieldsets ./resources/forms ./resources/users ./storage/forms ./public/assets {{app-env-id}}@ssh.{{region}}.frbit.app:/
shell

(You may not have all these folders on your local system: Only include folders which you do have.)

It works also the other way around. For example, if you have some edits done online and want them to be reflected in your local development environment:

# SYNC DOWN: from remote to local
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/content ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/users ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/blueprints ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/fieldsets ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/forms ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/users ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/storage/forms ./
$ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/public/assets' ./
shell

Found a tpyo?Edit