Score:0

"PHP Warning: require(drupal.php): failed to open stream"

bj flag

I have created two fresh installations of Drupal, one version 8.9.17 and the other 9.2.3 and have been trying to get the Drupal console to work so that I can generate a module.

I used the following command in Composer and successfully downloaded it.

composer require drupal/console:~1.0 \
--prefer-dist \
--optimize-autoloader \
--sort-packages \
--no-update

Then run the following to avoid a Symphony conflict error.

composer update

This downloaded the relevant files and dependencies but when I try to access it from the command line (see below)

$ ../../../../vendor/bin/drupal

I get the following error.

Warning: require(drupal.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project_name\vendor\bin\drupal(21) : eval()'d code on line 3 PHP Fatal error: require(): Failed opening required 'drupal.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project_name\vendor\bin\drupal(21) : eval()'d code on line 3

Fatal error: require(): Failed opening required 'drupal.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project_name\vendor\bin\drupal(21) : eval()'d code on line 3

I looked on the Drupal console website and the advice was

This can be caused by the ioncube loader extension

As i'm working with Xammp on Windows 10, ioncube isn't available by default in the php.ini file. What should I be looking for to solve this?

EDIT It has been pointed out to me that Drush now includes generating commands and should be used instead of Drupal console which appears to be obsolete.

cn flag
Last I heard (a while ago now) Drupal Console was obsolete and unmaintained - all of the `generate` commands are available with Drush though
bj flag
@Clive, Oh. I can't see that when I run Drush - https://pastebin.com/7BrZ4vXe but I have just looked on the Drush website and can see them listed there. Interesting, might need to do some more digging.
cn flag
Yeah I use it all the time: https://imgur.com/a/WiDdY3w
bj flag
@Clive, You are correct. Didn't realise it was listed under 'Global' - I'll need to check that out. Thanks!
miststudent2011 avatar
fr flag
@Clive one important and useful command missing in drush is entity type config export. Like node bundle config export. Which is present in Drupal console. Unless i am not aware of existing command.
cn flag
I don't think so @miststudent2011, I think that command is missing/not implemented like you say. Features provides similar functionality I think
miststudent2011 avatar
fr flag
@clive Yes, features provides similar functionality but it wont export fields storage config which makes bundle config export useless. Unless I have made mistake while expoting configs via features.
Score:1
bj flag

OK, so immediately after I posted the question I found the solution. I hope this helps anyone else in a similar situation.

The error is essentially saying that the drupal.php file cannot be found. So I went into the vendor/bin/drupal directory followed where the file was missing from:

vendor/drupal/console/bin/drupal

If you open that file, you will see the following code, which references the missing drupal.php file.

#!/usr/bin/env php
<?php
 
require 'drupal.php';

I compared this to Drush (which was working fine) and saw the Drush file was similar, but included the directory reference __DIR__. I updated the drupal.php file to the following and it now works as expected.

#!/usr/bin/env php
<?php
    
require __DIR__ . '/drupal.php';
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.