Customized Suzuki Intruder in French village
Photo: Copyright © 2014 Eelke Blok

Quick tip: generating a hash salt for Drupal 8

Drupal 8 will actively complain when your site does not have a hash_salt configured, which usually gets generated when installing the site. (The complaint, mind you, might be fairly obscure; your site might just say "The website encountered an unexpected error. Please try again later." Depending on your error reporting settings, the message might be a bit more helpful). If, for example, you "install" a site by copying over a database and files, you will not have this.

Update 26/21/2021: since writing this blog post, I found that basically, for Drupal's functioning, it does not matter what your hash salt is. You can put in any old string, which would be fine especially for a development system. The procedure below gets you something that is similar to what the official Drupal install procedure would produce.

When you need a fresh site hash, you can use the following Drush command.

drush php-eval 'echo \Drupal\Component\Utility\Crypt::randomBytesBase64(55) . "\n";'

Alternatively, if you would like to put it in a file, so that you can read the file from somewhere outside your webroot, you could do:

drush php-eval 'echo \Drupal\Component\Utility\Crypt::randomBytesBase64(55)' > salt.txt

To quote the comment from default.settings.php:

 * Example:
 * @code
 *   $settings['hash_salt'] = file_get_contents('/home/example/salt.txt');
 * @endcode

 

Comments

Add new comment