Drupal-console: [help] Test new Download Drupal8 + DrupalConsole instructions

Created on 6 Oct 2016  路  26Comments  路  Source: hechoendrupal/drupal-console

I am working on the docs for Download Drupal8 + DrupalConsole using the awesome DrupalComposer project

Install Composer
https://getcomposer.org/download/

Install DrupalConsole launcher tool

curl https://drupalconsole.com/installer -L -o drupal.phar
mv drupal.phar /usr/local/bin/drupal
chmod +x /usr/local/bin/drupal

Download Drupal + DrupalConsole

composer create-project \
drupal-composer/drupal-project:8.x-dev \
drupal8.dev \
--prefer-dist \
--no-progress \
--no-interaction

Change to new created directory

cd drupal8.dev/

Verify DrupalConsole downloaded versions

composer show | grep drupal/console

Verify DrupalCore downloaded version

composer show | grep drupal/core

Copy configuration files (make sure you answer yes to first question)

drupal init

Install Drupal (enter your DB credentials)

drupal site:install

Show available commands

drupal list

Test some commands

drupal generate:module
drupal generate:controller

drupal router:debug
drupal plugin:debug
drupal container:debug

Any feedback is appreciated

Hacktoberfest

Most helpful comment

Message

commands.yaml.unset.key.yml Unable to parse at line 2 (near " arguments:")

Fixed with rc8

All 26 comments

Yep, it works for me, but the command chain is broken it's return to me:

[Symfony\Component\Console\Exception\CommandNotFoundException]  
  Command "chain" is not defined.    

When i execute from outside drupal context, it's a bug?

@Bedotech we are bringing chain back to global executable also resurrecting site:new command.

I have tested the instructions and can confirm that it works

Followed the instructions, seems to work nice. I am not sure if that's an issue but I just want to mention that after the installation the services.yml gets 666 permission unlike settings.php which get 444. So on Status report I get:

Not protected
The file sites/default/services.yml is not protected from modifications and poses a security risk. You must change the file's permissions to be non-writable.

I had trouble with the installation instructions as listed above, and in the current README. Instead of drupal site:install, I needed to run drupal site:install --root=web; otherwise, Drupal Console asked me what installation profile to install, but did not list any installation profiles, and did not accept any of my answers, instead saying [ERROR] Value "" is invalid for anything input.

Expected Behavior

Drupal Console should find the Drupal root, or drupal init should find or prompt for the Drupal root and write it into a configuration file. Failing that, drupal site:install should provide a better / more informative error message when it cannot find any installation profiles.

@greg-1-anderson At this section on the instructions is where the root option is set.

Copy configuration files (make sure you answer yes to first question)

drupal init

Do you think we should have a better o more detailed explanation?

I think that the current instructions don't work quite right. I ran drupal init again, and then inspected the configuration file it wrote. I got:

application:
  options:
    learning: true
#    target: drupalvm.dev
#    uri: miltisite.dev
    generate-inline: false
    generate-chain: false
##    yes: false
    composer: false
    root: 'web'

That is greatly abbreviated, of course. However, the root: 'web' option is there. This implies to me that I should be able to run drupal list from the project root (folder containing composer.json), and not need to specify --root=web. However, the output of list is greatly abbreviated unless I include --root=web. Is this a bug, or am I doing something wrong?

Running Drupal Console version 1.0.0-rc6.

I ran settings:debug and saw that the settings contained:

 options.root                     web 

I changed the 'root' item in config.yml to a full path. This was correctly reflected in settings:debug, but did not improve my results with drupal list or other commands (--root=web still required for correct operation).

@greg-1-anderson what is your configuration OS, PHP and MySQL (which versions)?, are you using a VM? could you share your web/sites/default/settings.php file?

@jmolivas I am trying to get this to work in two environments:

  1. Local, with drupal-composer/drupal-project
  2. On Pantheon, in a project with a relocated document root

I am getting the same results in both environments. Also, on the local project, I got the same results when installing Drupal with Drush and when installing with Drupal Console (i.e. drush si and drupal site:install give me the same results). My web/sites/default/settings.php file is simply the default written by these tools; I'll post a trimmed version if you want to see it.

OS: MacOS 10.11.6
PHP: 7.0.11
Mysql: Ver 14.14 Distrib 5.7.14

Skipping all of the boilerplate, my random hash salt, etc., my settings.php contains:

$databases['default']['default'] = array (
  'database' => 'drupalconsoleothertest',
  'username' => '[REDACTED]',
  'password' => '[REDACTED]',
  'prefix' => '',
  'host' => '127.0.0.1',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);
$settings['install_profile'] = 'standard';
$config_directories['sync'] = 'sites/default/files/config_lotsofchars/sync';

Oh, also important: I have ./vendor/bin in my $PATH, so I am running the correct instance of Drupal Console:

$ which drupal
./vendor/bin/drupal

@greg-1-anderson did you installed the global executable using curl?

how was this drupal executable created?

@jmolivas I don't want to use the global executable, because I'm trying to set up an environment similar to how I want it to work on Pantheon -- i.e. we have a site-local Drupal Console, there is one $HOME directory per site, and ~/.console/config.yml specifies the root: of the single Drupal site in that $HOME. I tried with both the global and site-local config.yml, and I tried both relative and absolute paths in the root: element in that config.yml. I just realized that my test of the global config.yml probably wasn't valid, as I did not remove my config.yml file, but I don't think that is significant, since settings:debug showed the correct value for the root config element.

The drupal executable was created by the composer create-project command, per the instructions in this thread. It seems the bug (or feature request) is related to the site-local drupal not being able to identify the root of the site from Drupal Console's configuration when not being called by the global launcher.

Sorry, I just realized that I failed to mention up-front that I started these instructions at step two. That's why I'm getting different results. Hope this configuration is supported; I'd rather not install the global launcher on Pantheon.

@greg-1-anderson Glad you mentioned that about no global executable.

I did a quick fix for this and it's working on my local.

Can you copy/paste this at your bin/drupal.php file at vendor/drupal/console/bin/drupal.php?

<?php

use Drupal\Console\Utils\ArgvInputReader;
use Drupal\Console\Application;
use Drupal\Console\Bootstrap\Drupal;

set_time_limit(0);
$appRoot = getcwd() . '/';
$root = $appRoot;

$globalAutoLoadFile = $appRoot.'/autoload.php';
$projectAutoLoadFile = $appRoot.'/vendor/autoload.php';

if (file_exists($globalAutoLoadFile)) {
    $autoload = include_once $globalAutoLoadFile;
} elseif (file_exists($projectAutoLoadFile)) {
    $autoload = include_once $projectAutoLoadFile;
} else {
    echo PHP_EOL .
        ' DrupalConsole must be executed within a Drupal Site.'.PHP_EOL.
        ' Try changing to a Drupal site directory and download it by executing:'. PHP_EOL .
        ' composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader'. PHP_EOL .
        ' composer update drupal/console --with-dependencies'. PHP_EOL .
        PHP_EOL;

    exit(1);
}

if (!file_exists($appRoot.'composer.json')) {
    $root = realpath($appRoot . '../') . '/';
}

if (!file_exists($root.'composer.json')) {
    echo ' No composer.json file found at:' . PHP_EOL .
         ' '. $root . PHP_EOL .
         ' you should try run this command,' . PHP_EOL .
         ' from the Drupal root directory.' . PHP_EOL;

    exit(1);
}

$argvInputReader = new ArgvInputReader();

$configurationManager = new \Drupal\Console\Utils\ConfigurationManager();
$configuration = $configurationManager->loadConfiguration($root)
    ->getConfiguration();
if ($options = $configuration->get('application.options') ?: []) {
    $argvInputReader->setOptionsFromConfiguration($options);
}
$argvInputReader->setOptionsAsArgv();

if ($root === $appRoot && $argvInputReader->get('root')) {
    $appRoot = $argvInputReader->get('root');
    if (is_dir($appRoot)) {
        chdir($appRoot);
    }
    else {
        $appRoot = $root;
    }
}

$drupal = new Drupal($autoload, $root, $appRoot);
$container = $drupal->boot();

if (!$container) {
    echo ' In order to list all of the available commands you should try: ' . PHP_EOL .
         ' Copy config files: drupal init ' . PHP_EOL .
         ' Install Drupal site: drupal site:install ' . PHP_EOL;

    exit(1);
}

$configuration = $container->get('console.configuration_manager')
    ->getConfiguration();

$translator = $container->get('console.translator_manager');

if ($options = $configuration->get('application.options') ?: []) {
    $argvInputReader->setOptionsFromConfiguration($options);
}
$argvInputReader->setOptionsAsArgv();

$application = new Application($container);
$application->setDefaultCommand('about');
$application->run();

That works perfectly on my local system -- thanks so much for the fix. I'll try it on Pantheon tomorrow; should work the same as local.

Woot -- that works great. Would be cool to have the fix available in a tagged build.

@greg-1-anderson awesome, yes this will be included on rc7.

@greg-1-anderson New release tagged https://github.com/hechoendrupal/DrupalConsole/releases/tag/1.0.0-rc7 let me know if it works or if any new issues arises.

Great -- I'll build a brand new project and see if it works from the tagged build.

Works, but seeing commands.yaml.unset.key.yml Unable to parse at line 2 (near " arguments:") on every command, as previously reported. Thanks!

@greg-1-anderson got that message fixed new RC soon.

Message

commands.yaml.unset.key.yml Unable to parse at line 2 (near " arguments:")

Fixed with rc8

Was this page helpful?
0 / 5 - 0 ratings