Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access denied! [error] Drush command terminated abnormally due to an unrecoverable error. #3439

Closed
trepmag opened this issue Mar 6, 2018 · 4 comments

Comments

@trepmag
Copy link

trepmag commented Mar 6, 2018

Hello, I have an instance which on a particular hosting drush return "Access denied!":

garvey@marcus.com:~/web/dev/docroot$ drush -d
 [preflight] Config paths: /home/garvey/web/dev/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /home/garvey/web/dev/docroot/drush/sites,/home/garvey/web/dev/drush/sites
 [preflight] Commandfile search paths: /home/garvey/web/dev/vendor/drush/drush/src
 [bootstrap] Bootstrap to max [0.14 sec, 7.4 MB]
 [debug] Trying to bootstrap as far as we can [0.14 sec, 7.4 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalRoot() [0.15 sec, 7.54 MB]
 [bootstrap] Change working directory to /home/garvey/web/dev/docroot [0.15 sec, 7.54 MB]
 [bootstrap] Initialized Drupal 8.4.5 root directory at /home/garvey/web/dev/docroot [0.15 sec, 7.54 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalSite() [0.16 sec, 8.04 MB]
 [bootstrap] Initialized Drupal site default at sites/default [0.16 sec, 8.04 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.17 sec, 8.04 MB]
Access denied! [error]  Drush command terminated abnormally due to an unrecoverable error. [0.17 sec, 8.53 MB]

While it fails through drush the instance run successfully through apache?!...

Also, I could not identify any files or directory that the user running drush cannot read ?!...

Any tips on how I could try to identify what is wrong?

  • drush version: Drush Commandline Tool 9.1.0
  • drupal version: 8.4.5
@weitzman
Copy link
Member

weitzman commented Mar 6, 2018

I would review your settings.php in Drupal. It is probably assuming web requests. You can add a block like

if (PHP_SAPI !== 'cli' && $some_access_check) {
  exit('access denied')
}

@trepmag
Copy link
Author

trepmag commented Mar 6, 2018

Oh yes, it was that; I had an http authentification setup which wasn't correctly skip when in php cli context! Sorry for the disturbance and thank you very much for the tip!!!

@trepmag trepmag closed this as completed Mar 6, 2018
@gitressa
Copy link
Contributor

Thanks, this helped. I had added an exit in settings.php as part of forcing HTTPS, and I guess internally Drupal is not using HTTPS, giving me a "Drush command terminated abnormally due to an unrecoverable error" when executing for example drush st from within the Drupal installation directory. Interestingly, it worked if I used an alias (drush @alias st), perhaps because the base_url was defined in my drush alias?

Anyways, adding PHP_SAPI !== 'cli' in my settings.php did the trick:

// Force https
if ( (!array_key_exists('HTTPS', $_SERVER)) && (PHP_SAPI !== 'cli') ) {
  header('HTTP/1.1 301 Moved Permanently');
  header('Location: https://example.org'. $_SERVER['REQUEST_URI']);
  exit();
}

@jasonyarrington
Copy link

That one helped me out too. I was testing for a redirect and forgot to check that it was for the command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants