The plugin has been tested on Linux. It doesn't use any platform-specific functionality, but Windows and macOS are not covered by the automated tests yet.
Installation
Requirements
- PHP 8.2 or newer
- Composer 2.3 or newer
Your application must
- be distributed as a Composer package with a
namein itscomposer.json, - be available from a Composer repository, usually Packagist (see private repositories for alternatives), and
- be installed by its users with
composer create-project.
The plugin doesn't depend on any framework. It only uses the Composer API, so it works with Symfony, Laravel, Laminas, Slim, or plain PHP applications alike.
Step by Step
-
Require the plugin in your application:
composer require opencultureconsulting/updater -
Allow the plugin to run:
composer config allow-plugins.opencultureconsulting/updater trueSince Composer 2.2, plugins must be allowed explicitly. This adds the plugin to the
config.allow-pluginssection of yourcomposer.json:{ "config": { "allow-plugins": { "opencultureconsulting/updater": true } } }Don't skip this step! If the plugin isn't allowed in your
composer.json, Composer disables it when your users runcomposer create-projectnon-interactively, and theapp:upgradecommand won't be available. -
Make sure your
composer.jsonhas thetypeprojectand aname:{ "name": "acme/blog", "type": "project" } - Commit
composer.jsonandcomposer.lock, and publish a new release.
That's it! Starting with this release, your users can upgrade their installation with composer app:upgrade
. Note that
installations of older releases (without the plugin) have to be upgraded manually once.
Recommended Setup
The defaults work for many applications, but most applications benefit from some configuration:
- Ship your application with a
composer.lock(see below). - Configure the replace rules, so local configuration and user data are kept, and files removed from your application are deleted from the installations.
- Add a post-upgrade-cmd script to run database migrations and clear caches.
- Add a pre-upgrade-cmd script to enable a maintenance mode during the upgrade.
- Tell your users about the
app:upgradecommand in your installation instructions, e.g. by linking to the User Guide.
The examples show complete configurations for typical applications.
Shipping a Lock File
It is strongly recommended to commit your application's composer.lock
and to include it in your releases (i.e. not
to exclude it with export-ignore
in your .gitattributes
). Many applications don't, because Composer's
documentation recommends against committing the lock file for libraries
. But an application installed with
composer create-project
isn't a library, and a lock file has several advantages for it:
- Tested dependencies:
Every installation of a release gets exactly the versions of your dependencies you tested
the release with, both with
composer create-projectand withcomposer app:upgrade. Without a lock file, the dependencies are resolved anew on every installation, so your users might get newer, untested versions. - Faster and more reliable upgrades: Installing from a lock file doesn't need to resolve dependencies, which is faster and less likely to fail, e.g. because of a temporarily unavailable package.
- Predictable scripts:
Composer runs different scripts depending on whether there is a lock file. With a lock file,
composer installruns thepre-install-cmdandpost-install-cmdscripts. Without one, it resolves the dependencies likecomposer updateand runs thepre-update-cmdandpost-update-cmdscripts instead. This also applies tocomposer create-projectand to the dependency installation during an upgrade (see upgrade scripts).
If your release doesn't contain a lock file, the plugin removes the installation's existing lock file during the upgrade, so the new version's dependencies are resolved from scratch rather than installed from an outdated lock file.
Set the config.platform.php
option in your composer.json
to the lowest PHP version you support. Then the lock
file doesn't contain dependency versions which require a newer PHP version than your users might have, no matter
which PHP version you create the lock file with. The plugin ignores this setting when checking which versions your
users' servers can run, so it doesn't keep them from upgrading to releases requiring a newer PHP version.
{
"config": {
"platform": {
"php": "8.2.0"
}
}
}
Remember to raise this setting together with the PHP version in your require
section. Composer can't create a lock
file if the overridden PHP version doesn't meet your own requirements. Also note that some packages require a
minimum patch version, e.g. ~8.2.27
, so you might have to set a higher patch version than .0
.
Private Repositories
The plugin looks for new versions in the repositories configured in the installed application's composer.json
.
Packagist is used by default. If you distribute your application through a private Composer repository, e.g.
Private Packagist or a self-hosted Satis instance,
add it to your application's composer.json
:
{
"repositories": [
{
"type": "composer",
"url": "https://packages.acme.com"
}
]
}
Credentials are never stored in your application. Your users configure them in their auth.json
or with
composer config
, just like for any other private package:
composer config --global http-basic.packages.acme.com username password
Uninstalling
To remove the plugin from your application, run:
composer remove opencultureconsulting/updater
This also removes the file vendor/composer-updater.json
which holds the installed version. You may also remove the
allow-plugins
entry and the extra.composer-updater
section from your composer.json
.