craftcms/plugin-installer
Automate installing and managing Craft CMS plugins via Composer. Simplifies adding plugins to projects, handling dependencies, and keeping installs consistent across environments—ideal for CI/CD workflows and teams that want repeatable, scriptable plugin setup.
Install the Package
Add the installer to your project’s composer.json under extra.installer-plugins:
{
"extra": {
"installer-plugins": {
"craftcms/plugin-installer": {
"types": ["craft-plugin"],
"file": "vendor/craftcms/plugin-installer/src/PluginInstaller.php"
}
}
}
}
Run composer update to apply.
First Use Case: Installing a Plugin Install a Craft CMS plugin via Composer:
composer require vendor/plugin-name
The installer will automatically detect and install the plugin into Craft’s plugins/ directory (e.g., craft/config/plugins/).
Where to Look First
composer.json of installed plugins for type: "craft-plugin" metadata.Plugin Structure Ensure your plugin follows Craft’s conventions:
/vendor/
/your-vendor/
/plugin-name/
Plugin.php # Main plugin class (extends `craft\base\Plugin`)
services.php # Service definitions
variables.php # Twig variables
config.php # Default settings
Plugin.php: Must implement getName(), getVersion(), and init().composer.json: Include "type": "craft-plugin" and "extra": { "installer-name": "vendor/plugin-name" }.Local Development
composer require vendor/plugin-name --dev for local testing.ln -s /path/to/plugin-name /path/to/craft/cms/web/craft/config/plugins/
CI/CD Integration
composer install in CI to verify plugin installation.composer install --prefer-dist --no-dev in production to avoid dev dependencies.Post-Install Hooks Override Craft’s plugin installation logic by publishing assets or running migrations:
// In Plugin.php
public function init()
{
parent::init();
Craft::$app->getAssetManager()->publishAssetPath(
$this,
'your-vendor/plugin-name/assets',
'plugins/your-vendor-plugin-name/assets'
);
}
Plugin Not Detected
"type": "craft-plugin" in composer.json or incorrect installer-name.composer.json and run composer dump-autoload.Permission Issues
craft/config/plugins/.chmod -R 755 craft/config/plugins/
Plugin Overwrites
yourcompany/plugin-name).Craft Version Mismatch
composer.json:
"require": {
"craftcms/cms": "^4.0"
}
composer install -v to trace installation steps.storage/logs/ for plugin initialization errors.Custom Installer Logic
Extend the installer by creating a custom PluginInstaller class:
// In your plugin’s composer.json
"extra": {
"installer-name": "your-vendor/custom-installer"
}
Implement Composer\Package\PluginInstallerInterface.
Post-Install Scripts Use Composer scripts to run migrations or publish assets:
"scripts": {
"post-install-cmd": [
"@craft install-plugin your-vendor/plugin-name"
]
}
Multi-Plugin Projects
For monorepos or multi-plugin setups, use composer.json aliases:
composer require vendor/plugin-a vendor/plugin-b --with-all-dependencies
// In Plugin.php
public function init()
{
$this->setComponents([
'assets' => \craft\web\AssetManager::class,
]);
$this->assets->publishResourceLocation();
}
composer create-project vendor/plugin-name to scaffold a new plugin.How can I help you explore Laravel packages today?