Skip to main content

Managing an existing Drupal site via Composer

Run this in your terminal:

composer config repositories.drupal composer https://packages.drupal.org/8

How can I add Drupal modules my site with composer?

        composer require drupal/pathauto
        Using version ^1.0@RC for drupal/pathauto
        ./composer.json has been updated
        Loading composer repositories with package information
        Updating dependencies (including require-dev)
        Package operations: 3 installs, 0 updates, 0 removals
        - Installing drupal/token (1.0.0-rc1): Loading from cache
        > Drupal\Core\Composer\Composer::vendorTestCodeCleanup
        - Installing drupal/ctools (3.0.0-beta1): Downloading (100%)
        > Drupal\Core\Composer\Composer::vendorTestCodeCleanup
        - Installing drupal/pathauto (1.0.0-rc1): Downloading (100%)
        > Drupal\Core\Composer\Composer::vendorTestCodeCleanup
        Writing lock file
        Generating autoload files
        > Drupal\Core\Composer\Composer::preAutoloadDump
        > Drupal\Core\Composer\Composer::ensureHtaccess

How can I add Drupal themes my site with composer?

    composer require drupal/bootstrap
    Using version ^3.2 for drupal/bootstrap
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
      - Installing drupal/bootstrap (3.2.0): Downloading (100%)
    > Drupal\Core\Composer\Composer::vendorTestCodeCleanup
    Writing lock file
    Generating autoload files
    > Drupal\Core\Composer\Composer::preAutoloadDump
    > Drupal\Core\Composer\Composer::ensureHtaccess

composer.json

{
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0+",
    "require": {
        "composer/installers": "^1.0.21",
        "wikimedia/composer-merge-plugin": "~1.3",
        "drupal/pathauto": "^1.0@RC",
        "drupal/bootstrap": "^3.2"
    },
    "replace": {
        "drupal/core": "~8.2"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php."
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json"
            ],
            "recurse": false,
            "replace": false,
            "merge-extra": false
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
    },
    "repositories": {
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    }
}

Back to top