Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Quick tip: generating a hash salt for Drupal 8

Parent Feed: 

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

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web