Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to manage Drupal 8 projects using Composer and Drush

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 873
    Comment on it

    Drupal is revered as one of the magnificent CMS and development platforms to build websites. It is widely accredited for its flexibility that comes, in part, from the massive community across the project. The entire Drupal community is made up of more than 1 billion users that provide massive support in creating the beautiful themes and websites. In this blog I will share the insights about ways to manage the Drupal sites using Composer and Drush.

     

    Composer is the dependency manager for PHP and helps to find and download the dependency as per the requirement. On the other hand, Drush is a command line shell for Drupal.

     

    Installing Composer

    You can install the Drupal 8 Composer as per the installed Operating System of your computer. Have a look at the following links to get the idea for the same:

     https://getcomposer.org/doc/00-intro.md

    or

    https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04

     

    Please use the following command to easily install the drupal site using composer. This command will download the drupal in your project folder.

    $ composer create-project drupal-composer/drupal-project:8.x-dev my_project_name_dir --stability dev no-interaction

    By using the drupal composer, we can download or manage the module, themes, and other drupal specific dependencies from drupal.org. However, if you have created the project without the composer, you need to edit the project composer.json file for add module and themes dependencies etc.

     

    How to define the drupal.org as source of drupal packages

    Drupal.org provides the set of own directories and modules to use composer. However, we need to set and edit composer.json of your project.

    { 
        "repositories": { 
            "drupal": {
                "type": "composer",
                "url": "https://packages.drupal.org/8" 
            }
        }
    } 

    This composer configuration will look up the modules and themes etc from the drupal.org

     

    How to define the directories of drupal project should be downloaded

    You can set the correct path of directories for download the libraries etc.

    "extra": {
        "installer-paths": {
            "core": ["type:drupal-core"],
            "libraries/{$name}": ["type:drupal-library"],
            "modules/contrib/{$name}": ["type:drupal-module"],
            "profiles/contrib/{$name}": ["type:drupal-profile"],
            "themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/{$name}": ["type:drupal-drush"],
            "modules/custom/{$name}": ["type:drupal-custom-module"],
            "themes/custom/{$name}": ["type:drupal-custom-theme"]
        }
    }

     

    How to add drupal module using composer

    If you want to add any drupal module in your project, run the following command:

    $ composer require drupal/<modulename>

     

    For example:

    $ composer require drupal/path

    Note: If you run the above command with “require” then composer will automatically update your composer.json. Composer will download the module but will not install in your project. You need to install manually or using “drush”

    {
        "require": { 
            "drupal/path": "1.x-dev"
        }
    } 

     

    Drush provides a lot of commands to manage drupal projects. Drupal 8 drush can enable or disable any module using drush command and also any changes related to configuration etc.

    For example: Enable a module

    drush en <modulename> -y

    drush en path -y

     

    Please click the following links, to know more.

    https://drushcommands.com

    If you like the blog, don’t forget to share it across the social media channels like facebook, Twitter, LinkedIn, Quora and more. For any brickbats or queries regarding Drupal 8 projects, feel free to comment in the comment section below.

    How to manage Drupal 8 projects using Composer and Drush

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: