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

drush cr in fresh Drupal 8 install results in Missing $settings['hash_salt'] in settings.php #1050

Closed
shrop opened this issue Dec 13, 2014 · 38 comments

Comments

@shrop
Copy link

shrop commented Dec 13, 2014

drush cr in fresh Drupal 8 install results in Missing $settings['hash_salt'] in settings.php

Below is the full trace after the errors. I have tried a few installs of Drupal 8.0.0-beta3 and continue to get the same results. I am running php 5.5.

exception 'RuntimeException' with message 'Missing $settings['hash_salt'] in settings.php.' in /Users/shrop/Projects/www/core/lib/Drupal/Core/Site/Settings.php:130 [error]
Stack trace:
#0 /Users/shrop/Projects/www/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php(47): Drupal\Core\Site\Settings::getHashSalt()
#1 /Users/shrop/Projects/www/core/includes/utility.inc(35): Drupal\Core\PhpStorage\PhpStorageFactory::get('service_contain...')
#2 /Users/shrop/bin/drush/commands/core/cache.drush.inc(278): drupal_rebuild(Object(Composer\Autoload\ClassLoader), Object(Symfony\Component\HttpFoundation\Request))
#3 [internal function]: drush_cache_rebuild()
#4 /Users/shrop/bin/drush/includes/command.inc(359): call_user_func_array('drush_cache_reb...', Array)
#5 /Users/shrop/bin/drush/includes/command.inc(210): _drush_invoke_hooks(Array, Array)
#6 [internal function]: drush_command()
#7 /Users/shrop/bin/drush/includes/command.inc(178): call_user_func_array('drush_command', Array)
#8 /Users/shrop/bin/drush/lib/Drush/Boot/DrupalBoot.php(46): drush_dispatch(Array)
#9 /Users/shrop/bin/drush/drush.php(76): Drush\Boot\DrupalBoot->bootstrap_and_dispatch()
#10 /Users/shrop/bin/drush/drush.php(16): drush_main()
#11 {main}

@weyland-dev
Copy link

Any news on this one? I have the same problem.

@weitzman
Copy link
Member

Can you look at your settings.php file and see if you have $settings['hash_salt'] set to anything? Thats required in D8.

@TiMESPLiNTER
Copy link

Also facing this problem by executing drush cr in a Drupal8 beta2 installation. $settings['hash_salt'] is set to a random string value.

@shrop
Copy link
Author

shrop commented Dec 21, 2014

I have always had a salt value set as far as I know.

Interestingly, drush cr is now working for me since reinstalling with Drupal-8.0.0-beta4

@joestewart
Copy link

I think at one time I had traced to this commit -
d809c2d

But haven't checked lately or looked deeper.

On Sun, Dec 21, 2014 at 5:21 PM, Mark Shropshire notifications@github.com
wrote:

I have always had a salt value set as far as I know.

Interestingly,


Is now working for me since reinstalling with Drupal-8.0.0-beta4

—
Reply to this email directly or view it on GitHub
https://github.com/drush-ops/drush/issues/1050#issuecomment-67789582.

@Zekvyrin
Copy link

I also have the same error using 7.0.0-alpha7, but not using 7.0.0-alpha6.

@weitzman
Copy link
Member

That commit was buggy but has been fixed for some time. Do you guys have
more than on site under /sites? Maybe drush is picking the wrong one.

@dan-kessler
Copy link

We only have one [default].

@Zekvyrin
Copy link

@weitzman : Nop. Only one site, settings.php is in the default folder (/sites/default).

( Same thing happens when I use master branch. )

@weitzman
Copy link
Member

Folks - please confirm that this is happenning when you use very latest Drush and Drupal 8 beta4 or later.

@weyland-dev
Copy link

It was happening with beta3. Will test with beta4 and let you know asap

@Zekvyrin
Copy link

hm.. yes, indeed it worked with drupal beta4

@shrop
Copy link
Author

shrop commented Dec 22, 2014

drush cr works fine for me with Drush 7.0.0-alpha7 and Drupal 8.0.0-beta4. Seems it was broken with Drupal 8.0.0-beta3. May be able to close this one out.

@torstenzenk
Copy link

Having a hash salt string within settings.php and using the latest drush-master und D8-beta9 i get this error when i se drush cr:
exception 'RuntimeException' with message 'Missing $settings['hash_salt'] in settings.php.' in [error]
/mysite/core/lib/Drupal/Core/Site/Settings.php:130
Stack trace:
#0 /mysite/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php(47): Drupal\Core\Site\Settings::getHashSalt()
#1 /mysite/core/includes/utility.inc(53): Drupal\Core\PhpStorage\PhpStorageFactory::get('service_contain...')
#2 /home/me/.composer/vendor/drush/drush/commands/core/cache.drush.inc(282): drupal_rebuild(Object(Composer\Autoload\ClassLoader),
Object(Symfony\Component\HttpFoundation\Request))
#3 [internal function]: drush_cache_rebuild()
#4 /home/me/.composer/vendor/drush/drush/includes/command.inc(368): call_user_func_array('drush_cache_reb...', Array)
#5 /home/me/.composer/vendor/drush/drush/includes/command.inc(219): _drush_invoke_hooks(Array, Array)
#6 [internal function]: drush_command()
#7 /home/me/.composer/vendor/drush/drush/includes/command.inc(187): call_user_func_array('drush_command', Array)
#8 /home/me/.composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
#9 /home/me/.composer/vendor/drush/drush/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#10 /home/me/.composer/vendor/drush/drush/drush.php(11): drush_main()
#11 {main}
Are there any solutions or recommendations on this issue?

@kenorb
Copy link
Contributor

kenorb commented Mar 30, 2016

Just add:

$settings['hash_salt'] = 'CHANGE_THIS';

into your settings.php or settings.local.php file.

@ferdly
Copy link

ferdly commented Oct 22, 2016

Here is a really good article that explains the good advice by @kenorb: Drupal Easy -- specifically from a Pantheon POV

@therobyouknow
Copy link

therobyouknow commented Dec 21, 2016

@kenorb thank you that worked: for #1050 (comment)

Just add:

$settings['hash_salt'] = 'CHANGE_THIS';

into your settings.php or settings.local.php file.

I then ran drush cr when in mysite.dev/web (as an example) and the command completed without the error. I can also visit mysite.dev in the browser and now longer get unexpected error please try later error.

Thank you.

@cleverington
Copy link

Can confirm it works and is pretty much needed for Pantheon -> Acquia DevDesktop on Windows

I had to drop-tables and re-import and then cache-rebuild though.

@charlieartist
Copy link

@cleverington I had to make that change running Drupal 8.3.x and DevDesktop, as well, although I believe it would have been the same for other local dev environments. Luckily, though, I didn't need to drop the DB and reimport.

@greg-1-anderson
Copy link
Member

@carnnia Your problem above is unrelated to the things discussed in this closed issue. Please open a new issue, and compare behavior of Drush 8.1.15 with Drush 9.0.0-beta9 with your site.

@loopy3025
Copy link

I can confirm that this error also triggers sometimes when Drupal can't find the settings file. It happened to me when I wasn't referencing settings.local.php from my settings.php correctly. It is somewhat different in drupal 8 than drupal 7.

@brooke-heaton
Copy link

brooke-heaton commented Mar 21, 2018

I can confirm the above comment by @loopy3025 I am getting this error with drush9 though I have
$settings['hash_salt'] = ''; defined on my settings.php. I am unclear on what causes this but it is happening while referencing a settings.local.php in my settings.php

@paul94010
Copy link

I am now having this problem with Drupal 8.5.1 and Drush 9.2.1. I don't understand where the hash salt comes from. It is not on any settings.php files in any version of Drupal 8 that I am running. Who supplies it and when in the process. And maybe a bigger question is "why this added complexity".

@pimduijst
Copy link

I am having this issue as well on a clean D8.5.1 install with Drush 9.2.3. Maybe the most strange thing is that I do have a $settings['hash_salt'] value set...

@amritms
Copy link

amritms commented Apr 11, 2018

Same here, Fresh drupal 8.5.1 install via composer with drush 9.2.3. I have long hash value in $settings['hash_salt']

@davidjguru
Copy link

Well, I'm having the same issue with a multisite instalation after launch drush cr :-/
I can confirm that I have hash_salt registered in all occurrences of settings.php
So, what's the problem? What settings are Drush Lookin' for...?
drush status
Drupal version : 8.5.3
Site URI : default
PHP binary : /usr/bin/php7.2
PHP config : /tmp/LCIcHO
PHP OS : Linux
Drush script : /usr/local/bin/drush
Drush version : 9.3.0
Drush temp : /tmp
Drush configs : /var/www/html/dp_multisite/vendor/drush/drush/drush.yml
Drupal root : /var/www/html/dp_multisite
Site path : sites/default

@davidjguru
Copy link

Ok, that's my fault xD ...When you're using drush cr in a multisite installation, you have to launch the order within a project folder. Drush cr goes to look for the specific database related with the project and if you are in the global multisite folder, there is no database there xD. Ok.
Launching the drush cr within a project folder, everything is ok. The message goes out.

@ryanblackmore
Copy link

I've installed Drupal 8 with composer, arranged my sites/ folder for multisite and immediately encountered this problem. Drush gives the missing salt error even within when ran in a site folder. However, Drush will work by using the --uri= argument:
$ drush --uri=example.com cr

@venkatadapa
Copy link

Add below line of code in either settings.php or settings.local.php, This was solved the same error for me. Basically we need to set some hash salt for more security and it will be used in string encryption like password.
$settings['hash_salt'] = 'SOMESTRING';

@brightbold
Copy link

Another reason you might get this error: if you're in a Lando container (Pantheon recipe in my case) and you accidentally typed drush cr instead of lando drush cr.

@carnnia
Copy link

carnnia commented May 20, 2019

i don't have this issue when i setup a d8 site using /sites/default.
but when trying to setup multi-site:
sites/site1.local
sites/site2.local
...
if i copy sites/default to sites/site1.local after site install, then the issue with the hash_salt happens.
if i create sites/site1.local and go through the installation procees then:
/var/www/my-dev-work/web/sites/site1.local drush cr
[success] Cache rebuild complete.

@tarekdj
Copy link

tarekdj commented May 23, 2019

If your are in a multisite context execute the drush command inside the proper site folder.

@Salah-1
Copy link

Salah-1 commented Apr 19, 2020

Similar to @carnnia
I was getting the error "Missing $settings['hash_salt'] in settings.php line 146" when i do drush cache clear or site-install.
Solution:
copy the sites.php and then remove settings.php in /defaults folder if you have it.

cp sites/example.sites.php sites/sites.php(read the core/INSTALL.txt)
Hope it helps someone
I know its not related to the main issue discussed but people are landing here from google search like me.

@oprogramador
Copy link

oprogramador commented Jan 16, 2021

For me it also fails.

  • I cloned the Drupal repo (http://git.drupal.org/project/drupal.git with the d99b12fb9e7a6c07db49bb2eba0d465f88cd9fc7 commit)
  • I run composer install
  • I run composer require drush/drush
  • I added the following code to sites/default/default.settings.php after $databases = []; (removing $settings['hash_salt'] = '';):
$databases['default']['default'] = [
  'database' => 'foo',
  'username' => 'user',
  'password' => 'pass',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'collation' => 'utf8mb4_general_ci',
];
$settings['hash_salt'] = 'ZDE0YjYxZDI2MDNkZWNjNTY0YzZiMDc0';
  • I have the following error for drush cr:
⟩ ./vendor/bin/drush cr

In Settings.php line 196:
                                                   
  Missing $settings['hash_salt'] in settings.php.  
  • my environment:
⟩ ./vendor/bin/drush status
 Drupal version : 9.2.0-dev                                               
 Site URI       : http://default                                          
 PHP binary     : /usr/bin/php7.4                                         
 PHP config     : /etc/php/7.4/cli/php.ini                                
 PHP OS         : Linux                                                   
 Drush script   : /home/pierre/fooproject/vendor/dr 
                  ush/drush/drush                                         
 Drush version  : 10.3.6                                                  
 Drush temp     : /tmp                                                    
 Drush configs  : /home/pierre/fooproject/vendor/dr 
                  ush/drush/drush.yml                                     
 Drupal root    : /home/pierre/fooproject           
 Site path      : sites/default

@oprogramador
Copy link

for me, drush cr worked after cp sites/default/default.settings.php sites/default/settings.php

@greg-1-anderson
Copy link
Member

Folks, please be sure that your $settings['hash_salt'] is set to a random unguessable string. If you skip this step, your one-time-login links will not be secure.

@rhyoharianja
Copy link

Sorry, may be this reply pass for 1 year. but, i ever face same issue $settings['hash_salt'] even I've been set in settings.php or settings.local.php. But, I found and fix the problem with server user : group access. Coz, when I run drush cr with different user group then settings.php or with simple sentence "permission denied".
How to fix : use same user / group on execute drush command with settings.php access level or in the other mean make settings.php can be access / read by drush command

@Sandra-headscape
Copy link

also make sure you're not using require_once or include_once as that might also cause it to not populate the settings from a sub file (as I learned 😅 while migrating to d10/drush 12.1)

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