Drupal 8 - Set private file system path / directory

By xngo on December 22, 2019

In Drupal 8, a private file system path should be writable by Drupal but not accessible over the web. This path is used to store private files and it shouldn't be part of the Drupal installation directory.

I need to set this up for the Backup and Migrate module. It needs a Private Files Directory.

Set private file system path

Open your .../sites/default/settings.php and set an absolute path to the variable $settings['file_private_path'].

Drupal 8 - file_private_path in settings.php

Test private file system

To check that the private file system path is set correctly. Navigate to Configuration > File system and then check the followings:

  • Private file system path matches what you set in settings.php.
  • You get the new Private local files served by Drupal option under Default download method section.

Drupal 8 - Configuration > File system

Also, Drupal should create a .htaccess file in your private folder.


In case that your test of the private file system path failed and that you get the following errors:

Not fully protected
See https://www.drupal.org/SA-CORE-2013-003 for information about the recommended .htaccess file which should be added to the private:// directory to help protect against arbitrary code execution.


Your private:// stream is not configured.

These errors are triggered because your private directory was not created prior to setting the variable $settings['file_private_path']. To resolve this issue:

  • Run cron from Configuration > Cron.
  • Clear your cache from Configuration > Performance.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.