Deploy Grav with Git and rsync

Published

Updated

Reviewedbyfl

Deploy the code of a Grav site to fortrabbit with Git and keep the content on the environment. The Grav software template excludes pages, accounts, config and caches from deployments, and rsync moves the content up and down.

Keep Grav runtime files out of Git

The code lives in a Git repository, the content stays on the environment. See the deployment intro for connecting a repository. Add these rules to .gitignore in the project root:

# .gitignore

# Composer, installed by the build command
/vendor

# Written by Grav at runtime
/cache
/logs
/tmp
/backup
/images
/assets

# Owned by the environment, synced with rsync
/user/pages
/user/accounts
/user/data
/user/config
shell

Deployment settings

The software template preconfigures the matching deployment settings when Grav is chosen as software: the replace strategy with the same paths as exclude patterns, a composer install build command, and a post-deploy command that recreates the empty runtime folders:

$ mkdir -p logs tmp backup images assets user/pages user/accounts user/data user/config
shell

Grav refuses to boot when one of those folders is missing, and none of them are in the repo.

Content with rsync

Content moves with rsync, in both directions:

# SYNC UP: local pages to the environment
$ rsync -av ./user/pages/ {{app-env-id}}@ssh.{{region}}.frbit.app:user/pages/

# SYNC DOWN: pages edited in the admin panel back to the local project
$ rsync -av {{app-env-id}}@ssh.{{region}}.frbit.app:user/pages/ ./user/pages/
shell

Seed user/config the same way on first setup. After that it belongs to the environment.

Plugins and themes count as code here. Install them locally, commit, then push — a plugin installed through the admin panel on the environment is gone after the next deployment. Configuration goes the other way: the admin panel writes to user/config, and so do plugins that generate their own secrets, so that folder is excluded from deployment and changes there have to be made on the environment.

Written by a human. Review, grammar checks and typo fixes by AI.

AI use & editorial processEdit on GitHub ↗