👀 Get a glimpse of Kirby 5 Learn more
Skip to content

Install & update via Composer

What is Composer?

Composer is a dependency manager for PHP. If you know npm, it's exactly that but for PHP. It allows you to install and update dependencies with simple commands on the command line.

About this tutorial

This guide describes one of several ways you can install and update Kirby. See the overview page for all supported ways.

Installing Composer

If you have never used Composer before, you first need to install it. Please follow the instructions on the Composer website.

Starting a new project

Once you have installed Composer, run the following command to set up a new Kirby installation with the Starterkit:

composer create-project getkirby/starterkit your-project

You can alternatively set up the Plainkit if you want:

composer create-project getkirby/plainkit your-project

All Composer packages are generally installed in the vendor directory. Kirby however is automatically installed in the kirby directory, so that you can get started right away.

It is generally recommended to exclude the vendor as well as the kirby directory from version control. If you use Git, add them to your .gitignore file. Your .gitignore should now look something like this:

...

/kirby
/vendor

...

Switching an existing Kirby site to a Composer setup

If you have an existing site and want to use Composer with it, that's possible as well.

The Composer magic is all contained in the composer.json file. The most basic version looks like this:

composer.json
{
  "require": {
    "getkirby/cms": "^4.0"
  },
  "config": {
    "optimize-autoloader": true
  }
}

Save this file in the root of your Kirby project and run the following command:

composer install

Installing Kirby to a custom directory

If you want to use a different location for the kirby directory, you can change it in your composer.json:

composer.json
{
  "require": {
    "getkirby/cms": "^4.0"
  },
  "config": {
    "optimize-autoloader": true
  },
  "extra": {
    "kirby-cms-path": "kirby" // change this to your custom path
  }
}

Afterwards update the installation with:

cd your-project
composer update

You will also need to modify your site's index.php so that it can find the Kirby installation:

index.php
<?php

require '<your-path>/bootstrap.php';

echo (new Kirby)->render();

If you moved the kirby directory to a different directory level (outside of the webroot or into a subdirectory), you will also need to override the index root like so:

index.php
<?php

require '<your-path>/bootstrap.php';

echo (new Kirby([
  'roots' => [
    'index' => __DIR__
  ]
]))->render();

Disabling the custom path completely

If you prefer to have the CMS installed to the vendor directory, you can disable the custom path entirely:

composer.json
{
  "require": {
    "getkirby/cms": "^4.0"
  },
  "config": {
    "optimize-autoloader": true
  },
  "extra": {
    "kirby-cms-path": false
  }
}

The index.php file needs to be changed so that it can find Kirby and so that Kirby can find the site data:

index.php
<?php

require 'vendor/autoload.php';

echo (new Kirby([
  'roots' => [
    'index' => __DIR__
  ]
]))->render();

Updating Kirby

If you want to update Kirby to the latest version, all you need to do is to run the following command:

composer update getkirby/cms

Composer will now look for the latest version that matches your version constraint in the composer.json file. You can learn more about this in the Composer documentation.

By changing the Kirby version in your composer.json, you can make Composer install a different version of Kirby. Very useful is the special version dev-develop, which will install the current development version of Kirby straight from GitHub.

Kirby uses the Semantic Versioning scheme:
{major}.{minor}(.{patch})

Major releases (e.g 4.0 to 5.0) may contain breaking changes and deprecations. In such a case, you might have to update your code and plugins used in your installation. You can find breaking changes of a new release in the changelogs. If you are updating from older versions, multiple changelogs may apply. Always read them carefully to identify potential issues.

Minor and patch releases (e.g. 4.1 to 4.2 or 4.1 to 4.1.1) can generally be applied without changes to your site code.

Note that the major version of Kirby 3 was the second number (e.g. the major version of Kirby 3.9.0 is 9). So e.g. updates from Kirby 3.8 to Kirby 3.9 also came with breaking changes.

In any case, please never update a live website directly on the server. Test updates locally first to see if something breaks.

Using Composer for Kirby plugins

Installing plugins with Composer

Many Kirby plugins also support installation via Composer. As you now have a Composer setup, you only need to add them to your composer.json file and run composer update. This will automatically install the plugins to the site/plugins directory for you.

Alternatively, you can run composer require <plugin-name>, which will install the plugin and add it to your composer.json for you.

If you want, you can add the plugin to your .gitignore file. If you prefer, you can skip this step and commit the plugin code to your site repo (e.g. if you want to enable other team members to work on the site without having to run Composer or if you don't want to run Composer when deploying your site).

Custom plugins directory path

If your plugins directory is in a non-standard location, you can change it like this:

composer.json
{
  "require": {
    "getkirby/cms": "^4.0",
    "superwoman/superplugin": "^1.0"
  },
  "config": {
    "optimize-autoloader": true
  },
  "extra": {
    "kirby-plugin-path": "site/plugins" // change this to your custom path
  }
}

Using Composer for other dependencies

Of course, you can also install other dependencies like general PHP libraries this way. The libraries you install will automatically be available from your site's code, e.g. in your templates, controllers and models.