/* drucafe */

Thursday, February 11, 2016

Install Drupal 8 console on Windows using composer

Drupal console is a command line tool for Drupal module developers for generating initial module code and for admins to do some administrative tasks. In order to install it on my Windows 7 with XAMPP and with existing composer, following the installation docs, I entered the command:

C:>composer global require drupal/console:@stable
(This installs the stable release instead of latest release)

This gave me the following output.

Hint: optionally turn off xdebug before running composer if you want it to run faster (comment line zend_extension = "I:\xampp\php\ext\php_xdebug.dll" in file I:\xampp\php\php.ini and then restart Apache).

Changed current directory to C:/Users/User1/AppData/Roaming/Composer
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing composer/installers (v1.0.23)
    Downloading: 100%

  - Installing symfony/dom-crawler (v2.6.13)
    Downloading: 100%

etc... long list
etc...

  - Installing drupal/console (0.7.14)
    Downloading: 100%

symfony/dom-crawler suggests installing symfony/css-selector ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
symfony/debug suggests installing symfony/http-kernel ()
symfony/dependency-injection suggests installing symfony/proxy-manager-bridge (Generate service proxies to lazy load them)
symfony/console suggests installing symfony/process ()
Writing lock file
Generating autoload files

Then I checked that the file exists:
C:\Users\User1\AppData\Roaming\Composer\vendor\drupal\console\bin\console.php

Then I checked that the file exists:
C:\Users\User1\AppData\Roaming\Composer\vendor\bin\console.bat

This console.bat file contains:
@ECHO OFF
SET BIN_TARGET=%~dp0/../drupal/console/bin/console
php "%BIN_TARGET%" %*

The console.bat is supposed to run the Drupal 8 console directly from Windows command line from Drupal project root. I had installed Drupal 8 before, so I copied it to my Drupal 8 project root and renamed from console.bat to drupal.bat. Then I ran the file and got error:
I:\xampp\htdocs\myd8project>drupal
Could not open input file: I:\xampp\htdocs\myd8project\/../drupal/console/bin/console

The drupal.bat needs a little change. The BIN_TARGET must be set to the console.php file that we checked before:
@ECHO OFF
SET BIN_TARGET=C:\Users\User1\AppData\Roaming\Composer\vendor\drupal\console\bin\console.php
php "%BIN_TARGET%" %*

Now running drupal.bat gives output:
I:\xampp\htdocs\myd8project>drupal
Drupal Console version 0.7.14
Usage:
 command [options] [arguments]
Options:
 --help (-h)           Display this help message
 etc...
 etc...

I am not sure but it seems to me that turning off xdebug speeds up the drupal console execution.

Updating the console

It might not be obvious but this isn't the latest console version. That's because we initially used the @stable option while installing the console. So there are some differences between the available commands and what the docs say, e.g. in case of version 0.7.14 there is no "about" command.  All available commands can be listed by
> drupal list

So if you type a command in the console that is in the docs and it's not available, then you might update the console:
> drupal self-update

In my case, it updated to version 0.10.9 and the number of available commands increased significantly.



1 comment: