An OSTraining member asked how they could set up a Drupal 8 private file system.
In Drupal 7 you could do this from the configuration at Administrator > Configuration > Media > File System.
In Drupal 8, we have to set the private path manually.
- Create a directory for the private files to be saved in:
You may want to use a name that won’t be considered important. For this tutorial, I have simply called it ‘private’.
- Go to your sites/default/settings.php. On line 533 you should find the setting we need to edit hashed out:
- Remove the hash and enter the path for your private directly. In my case, this is ‘sites/default/files/private’:
- Save and close settings.php file
- Flush the cache, which you can find in Administration > Configuration > Development > Performance:
- Go to the File System and see if Drupal is detecting the private file storage: Administrator > Configuration > Media > File system
- Select the private directory and save this configuration.
Drupal should automatically include a new .htaccess file inside the folder.
Now you have a private directory to store your files in.