Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademers/17ffa475d3226a1e33272cdb8f2d9338 to your computer and use it in GitHub Desktop.
Save ademers/17ffa475d3226a1e33272cdb8f2d9338 to your computer and use it in GitHub Desktop.

How I Install and Uninstall Craft CMS Plugins

⏳ 2 minute read

In this article, I describe the steps that I follow to install Craft CMS 3.5.x plugins.

Assumptions

  • Craft 3.5.x is installed in local development and production environments.
  • Composer 1.3.0 or later is installed in local development and production environments.
  • Access to a command line interface (CLI) in local development and production environments.

Installing a Craft CMS Plugin

In Local Development Environment

I'll be using Pixel & Tonic's Redactor plugin as an example. The latest version (at time of writing) is 2.8.5 as per the Redactor plugin page in the Craft Plugin Store.

  1. From the command line in the Craft project root, run:
    1. composer require craftcms/redactor:2.8.5 to add the Redactor Composer package to the composer.json file and install it with the version constrained to 2.8.5.
    2. craft plugin/install redactor to install the Redactor plugin with handle redactor in Craft itself.
    3. ./craft migrate/all to run plugin database migrations.
    4. ./craft project-config/apply to apply project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  2. Verify that the plugin was installed by visiting the Plugins section in the Craft control panel at http://example.test/admin/settings/plugins and is working as expected.

In Production Environment

  1. From the command line in the Craft project root, run:
    1. ./craft backup to backup the Craft database.
    2. composer install to install the plugin Composer package that I previously installed in my local development environment.
    3. ./craft migrate/all to run all database migrations.
    4. ./craft project-config/apply to apply project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  2. Verify that the plugin was installed by visiting the Plugins section in the Craft control panel at http://example.test/admin/settings/plugins and is working as expected.

Uninstalling a Craft CMS Plugin

In Local Development Environment

From the command line in the Craft project root, run:

  1. craft plugin/uninstall redactor to uninstall the Redactor plugin with handle redactor.
  2. composer remove craftcms/redactor to remove the Redactor Composer package from the composer.json file.

In Production Environment

  1. From the command line in the Craft project root, run:
    1. ./craft backup to backup the Craft database.
    2. composer install to uninstall the plugin Composer package that I previously uninstalled in my local development environment.
    3. ./craft migrate/all to run all database migrations.
    4. ./craft project-config/apply to apply project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  2. Verify that the plugin was uninstalled by visiting the Plugins section in the Craft Control Panel at http://example.com/admin/settings/plugins.

Automating the Craft CLI Commands

To avoid running the above Craft CLI commands manually, I've added the following Composer command events with the relevant Craft CLI commands to the scripts section of my Craft project's composer.json file.

"pre-update-cmd": [
    "@php craft backup/db"
],
"post-update-cmd": [
    "@php craft migrate/all",
    "@php craft project-config/apply",
    "@php craft clear-caches/all"
],
"pre-install-cmd": [
    "@php craft backup/db"
],
"post-install-cmd": [
    "@php craft migrate/all",
    "@php craft project-config/apply",
    "@php craft clear-caches/all"
]

By following the steps above, I can confidently install Craft plugins in my local development and production environments.

To learn how I update plugins, read my article titled How I Update Craft CMS 3.5.x and Craft CMS Plugins.

— Andrea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment