2

I cannot execute drush in my environment. Drush is installed using

php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush.phar');" > /usr/local/bin/drush \
&& chmod +x /usr/local/bin/drush \
&& drush --yes init

status seems ok:

root@c0ec24eaf070:/var/www/html# drush status
 Drupal version         :  7.43                                    
 Site URI               :  http://localhost                        
 Database driver        :  mysql                                   
 Database hostname      :  172.20.0.3                              
 Database port          :  3306                                    
 Database username      :  root                                    
 Database name          :  drupal                                  
 PHP configuration      :  /usr/local/etc/php/php.ini              
 PHP OS                 :  Linux                                   
 Drush script           :  /usr/local/bin/drush                    
 Drush version          :  8.1.3                                   
 Drush temp directory   :  /tmp                                    
 Drush configuration    :  /var/www/html/sites/default/drushrc.php 
 Drush alias files      :                                          
 Drupal root            :  /var/www/html                           
 Drupal Settings File   :  sites/default/settings.php              
 Site path              :  sites/default                           

but any command (such as watchdog-delete) fail with:

root@c0ec24eaf070:/var/www/html# drush watchdog-delete all

Fatal error: Call to undefined function module_exists() in     phar:///usr/local/bin/drush/commands/core/drupal/environment_7.inc on line 187
Drush command terminated abnormally due to an unrecoverable error.                                                                                                   [error]
Error: Call to undefined function module_exists() in phar:///usr/local/bin/drush/commands/core/drupal/environment_7.inc, line 187

FYI The environment is a drupal:7.43 docker container and goes ever worse if I upgrade to 7.50

root@80116582cabe:/var/www/html# drush status
 Drupal version         :  7.50                                    
 Site URI               :  http://localhost                        
 Database driver        :  mysql                                   
 Database hostname      :  172.20.0.3                              
 Database port          :  3306                                    
 Database username      :  root                                    
 Database name          :  drupal                                  
 PHP configuration      :  /usr/local/etc/php/php.ini              
 PHP OS                 :  Linux                                   
 Drush script           :  /usr/local/bin/drush                    
 Drush version          :  8.1.3                                   
 Drush temp directory   :  /tmp                                    
 Drush configuration    :  /var/www/html/sites/default/drushrc.php 
 Drush alias files      :                                          
 Drupal root            :  /var/www/html                           
 Drupal Settings File   :  sites/default/settings.php              
 Site path              :  sites/default                           

root@80116582cabe:/var/www/html# drush watchdog-delete all

Fatal error: Uncaught Error: Call to undefined function cache_get() in /var/www/html/includes/module.inc:754
Stack trace:
#0 /var/www/html/includes/module.inc(954): module_implements('system_theme_in...')
#1 /var/www/html/modules/system/system.module(2511): module_invoke_all('system_theme_in...')
#2 /var/www/html/includes/theme.inc(798): _system_rebuild_theme_data()
#3 /var/www/html/includes/theme.maintenance.inc(57): list_themes()
#4 /var/www/html/includes/bootstrap.inc(2857): _drupal_maintenance_theme()
#5 /var/www/html/includes/errors.inc(179): drupal_maintenance_theme()
#6 /var/www/html/includes/bootstrap.inc(2594): _drupal_log_error(Array, true)
#7 [internal function]: _drupal_exception_handler(Object(Error))
#8 {main}
  thrown in /var/www/html/includes/module.inc on line 754
Drush command terminated abnormally due to an unrecoverable error.                                                                                                   [error]
Error: Uncaught Error: Call to undefined function cache_get() in /var/www/html/includes/module.inc:754
Stack trace:
#0 /var/www/html/includes/module.inc(954): module_implements('system_theme_in...')
#1 /var/www/html/modules/system/system.module(2511): module_invoke_all('system_theme_in...')
#2 /var/www/html/includes/theme.inc(798): _system_rebuild_theme_data()
#3 /var/www/html/includes/theme.maintenance.inc(57): list_themes()
#4 /var/www/html/includes/bootstrap.inc(2857): _drupal_maintenance_theme()
#5 /var/www/html/includes/errors.inc(179): drupal_maintenance_theme()
#6 /var/www/html/includes/bootstrap.inc(2594): _drupal_log_error(Array, true)
#7 [internal function]: _drupal_exception_handler(Object(Error))
#8 {main}
  thrown in /var/www/html/includes/module.inc, line 754
1

It resolved to be simply the missing mysql-client package :-(

So:

apt-get install -y mysql-client

resolves the issue.

0
1

I wanted to provide an alternate answer in case other people are experiencing this issue but already have MySQL installed. When I tried executing Drush commands, I was getting

PHP Fatal error: Call to undefined function module_exists() in /usr/local/src/drush/commands/core/drupal/environment_7.inc on line 187

I am running Drupal 7 on a Debian server and my issue was fixed by restarting MySQL and then restarting Apache:

/usr/sbin/service mysql start

service apache2 restart

Edit: in once case, I was receiving this error because the database user password had somehow been changed and did not match the credentials in Drupal's settings.php file. In that case, I restored the password in MySQL to match what was in the settings.php file. Using command line and logged into MySQL (MySQL version 5.5.3):

SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password');
0

For Windows users, add the Path to Environment Variables where mysql.exe sits.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.