Deploy Kirby with git and rsync
This is yje recommended workflow to deploy Kirby using Git. It's a bit more advanced, but worth the mile when maintaining a project.
# Get ready
- Read the Kirby Composer guide from the official Kirby docs.
- Have a local development environment including PHP and Composer running.
- Have an Account with fortrabbit and GitHub.
- Install the fortrabbit GitHub app at GitHub.
# Rundown
- Install Kirby locally
- Start Git and integrate with GitHub
- Connect your GitHub repo with fortrabbit
- Synchronize contents with rsync
# Install Kirby locally with Composer
# 1. Create a local (on your computer) Kirby project folder with Composer: $ composer create-project getkirby/plainkit {{app-env-id}}shell
Kirby offers a "starterkit" (with some demo contents and a theme with some templates) and a "plainkit" with no contents at all (which is used here). There is also the "composerkit" which has a different folder structure.
Maybe you also have a project running locally and are just looking for ways to deploy that. Continue with the next steps.
# Configure Kirby for git deployment with rsync
Open your local Kirby project folder with your text editor or IDE. Open the (hidden) .gitignore file at the top level to tell Git to ignore some folders. Add these three ignore rules if not already present:
# .gitignore # Kirby itself /kirby # Composer dependencies /vendor # Stuff you are creating /contentshell
The setting above will also keep the /content folder out of Git. This is our opinionated way of doing it for this workflow. It will help keeping your repo tidy by separating code from content. But you will need to run dedicated rsync commands to deploy and update the "contents" (see below). You can also decide to not touch the .gitignore so that you can deploy everything with Git all together.
At this point you should be able to run the project in your local development environment already. We highly recommend to develop the site locally, use fortrabbit for staging and production.
# Init Git and add GitHub
See the git deployment intro to get an idea how to connect a local repo to the GitHub remote and enable automatic deployment by installing the fortrabbit GitHub App with GitHub account.
Here is an example creating a repo from your local code base and using git command line and GitHub CLI to setup a local repo, and connect it to .
# Setup local git repo $ git init $ git add -A $ git commit -am 'Init' # GitHub CLI to create/connect remote Git repo $ gh repo new # Follow the steps # Push an existing local repository to github.com # Add as remote and assign current branch as 'origin'shell
At the end, the Git repo at GitHub is created and content already pushed. From now on you only need to run add, commit and git push to send code changes to GitHub.
# Connect your GitHub repo with fortrabbit
Now, the last step is to setup and connect an app on fortrabbit. Start the process in the fortrabbit dashboard:
Choose Kirby as software preset. Use Git deployment and select the Git repo that you have created previously. At the end the end of the process, start the first deployment and lean back. At this stage you have deployed a semi broken Kirby installation. That's because the content is missing. Let's fix this with the next step.
If you already created an (new empty) app at fortrabbit, connect the repo branch through settings.
# Synchronize contents
As mentioned, deployment of code (templates and configuration) and dependencies (Kirby and Composer) is done via Git deployment. Deploying the content is a separate step. We recommend to use rsync to upload or download new contents to and from your remote fortrabbit environment. See also our rsync article. On your local computer in the Terminal in the kirby project folder execute:
# SYNC UP: from local content folder and it's files to remote $ rsync -av ./content/ {{app-env-id}}@ssh.{{region}}.frbit.app:content/shell
It works also the other way around. For example in a case, where you have done some edits online and want those changes to be reflected in your local development environment:
# SYNC DOWN: from files from remote content folder to local folder $ rsync -av {{app-env-id}}@ssh.{{region}}.frbit.app:content/ ./content/bash
You can also use SFTP to synchronize the content folder.
# Going forward
From now on you can git push to trigger a deployment to fortrabbit via GitHub.