Tuesday 22 November 2022

Install Drush Globally

 To install Drush globally follow below steps.

1. Run below command, To install Drush 8.x required for Drupal 8+.

    composer global require drush/drush:dev-master

2. Now run below command to add Drush to your system path.

         export PATH="$HOME/.composer/vendor/bin:$PATH"

3. Run below command to update to a newer version.

         composer global update

To install specific version of Drush, run below command.

        composer global require drush/drush:6.1.0

Some of the below common used Drush commands.

drush cc or cache:clear => To clear cache. When we run this command, will give some options to execute as below

          [0] Cancel

    [1] drush

    [2] theme-registry

    [3] router

    [4] css-js

    [5] render

    [6] plugin

    [7] bin

    [8] views

drush cr or cache:rebuild => Rebuild a Drupal 8 site.
drush updb or updatedb => Apply any database updates required (as with running update.php)
drush updbst or updatedb:status => List any pending database updates.
drush uli or user:login => Display a one time login link for user ID 1, or another user.
drush pml => To list modules
drush en module_name => To enable module
drush pmu => To uninstall module
drush site:install => To install Drupal site with Drush command.
drush sqlc or sql:cli => Open a SQL command-line interface using Drupal's credentials.
drush sql:dump => Exports the Drupal DB as SQL using mysqldump or equivalent.
drush sqlq or sql:query => Execute a query against a database.


Create Drupal 9 Project with Composer

 For Drupal 9, We should use "drupal/recommended-project" composer template. This will ensure that Drupal core dependencies are same as the official Drupal release.

Composer command is as below to create Drupal 9 project

composer create-project drupal/recommended-project first_drupal9_site

This command will create a project in "first_drupal9_site" and automatically will execute composer install to download latest stable version of Drupal and all its dependencies.

Now first_drupal9_site directory will have files as below.

1. composer.json (file)

2. composer.lock (file)

3. vendor (Directory)

4. web (Directory)

The web root will be "web" directory. Except "web" directory, all other files "composer.json, composer.lock, vendor" will not accessible to the web server. 


To install Drupal 9 site, now access your localhost and access web directory. Follow the steps as per installation asks. Once these steps will finish, your first Drupal 9 site will ready.


To install specific version, run below composer command.

composer create-project drupal/recommended-project:9.4.8 first_drupal9_site


To do modified installation

Before composer install execution, if I need to modify some of the properties of the downloaded composer.json then we have to use --no-install flag while running composer create-project

Example, if I want to rename the subdirectory "web" to something else. Follow below steps

  • Run command composer create-project --no-install drupal/recommended-project first_drupal_site 
  • Change directories to first_drupal_site and edit the composer.json file to suit your needs.

    For example, to change the sub-directory from 'web' to something else, the keys to modify are the 'extra' sub-keys 'web-root' (under 'drupal-scaffold') and 'installer-paths'.

  • Run composer install to download Drupal and all its dependencies. 
To download contributed module and contributed theme with composer follow below steps.
  • Run composer require drupal/module_name. eg. composer require drupal/token
  • This needs to be executed at the root of your Drupal install but not at the same level as the core directory.
Composer will then automatically update your composer.json, adding the module to all the other requirements in the list, like this:

{
    "require": {
        "drupal/token": "^1.5"
    }
}
Composer will download the module and all the possible dependencies it may have.

Specifying a version
You can specify the version of the module / theme you want to download as follows:

composer require 'drupal/module_name:version'
(...where version is replaced with a Composer version or version constraint.)

For example:
composer require 'drupal/token:^1.5' 
composer require 'drupal/simple_fb_connect:~3.0' 
composer require 'drupal/ctools:3.0.0-alpha26' 
composer require 'drupal/token:1.x-dev' 

To avoid problems on different terminals/shells, surround the version in quotes as in the examples above.

Note!: On Windows, single quotes actually might break the version specification and lead to failure to install with 'Could not parse version constraint .....': Invalid version string "....'".

Without the quotes, e.g.:
composer require drupal/ctools:^3.7 or with double quotes instead of single quotes, e.g.:
composer require "drupal/ctools:^3.7" works well.

Reference link Drupal.org

Monday 21 November 2022

Enable PHP OPCache in Xampp

To install Drupal 8 and upper version, PHP OPCache extension is required. Untill we will not enable this, Drupal 8+ versions can not be installed.

To enable this extension, Please follow below steps.

1. Open php.ini file which is configuration file for PHP.

2. Search for "Dynamic Extensions" keyword.

3. Under this heading, Either search for ";zend_extension=opcache" and uncomment this line by removing ";" or add new line by adding below code

   zend_extension="C:\xampp\php\ext\php_opcache.dll"

4. Make sure the "zend_extension" should have the exact path to the opcache.dll file.

5. opcache.dll file exists in xampp > php > ext directory.

6. Save the php.ini file.

7. Restart the apache service.

8. Now try to install Drupal 8+, issue of PHP OPCache fixed.


To get good performance, following settings for PHP OPCache are recommended.

opcache.memory_consumption=128

opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4000

opcache.revalidate_freq=60

opcache.fast_shutdown=1

opcache.enable_cli=1