9

I can not enable the private folder getting the warning as below:

Warning: file_exists(): Unable to find the wrapper "private" - 
did you forget to enable it when you configured PHP? in file_save_htaccess() 
(line 365 of core/includes/file.inc).

It's Drupal 8.6.12, multisite config, other sites use private folders.

How can I fix it ?

3
  • What action are you taking to get that error message?
    – Clive
    Mar 15, 2019 at 13:36
  • 1
    The error might be a bit misleading by the way: it's Drupal that provides the private stream wrapper, not PHP itself, so the problem is in the site config rather than PHP config
    – Clive
    Mar 15, 2019 at 13:39
  • Just admin access like /admin/config
    – Paul Paku
    Mar 15, 2019 at 14:38

2 Answers 2

14

Here are the necessary steps:

  1. Create a directory on the server. This is typically done via SSH. For instance assuming Apache under Ubuntu, the following command can be used: sudo -u www-data mkdir -p /var/www/html/web/sites/default/files/private
  2. Tell Drupal about your directory by editing your settings.php file. You need to have a line like the following:

     $settings['file_private_path'] = '/var/www/html/web/sites/default/files/private';
    
  3. Important: clear the Drupal cache, for example with drush cr or by going to the page /admin/config/development/performance in your browser.

  4. In the browser's address bar, go to /admin/config/media/file-system. You should see "Private local files" in the "Default download method" option. If not, then please visit the /admin/reports/status page to see any error messages. Make sure that PHP can write in the directory. Often, for this to work, the directory has to be writable for the www-data user.

For more documentation, go to https://www.drupal.org/docs/8/core/modules/file/overview#private-file-system.

2
  • 6
    Clearing cache is very important. If you don't clear cache the private file system method will not become available.
    – anoopjohn
    Nov 1, 2019 at 20:35
  • @anoopjohn: I didn't even think about doing this or why it would be necessary but this fixed the problem!
    – uberhacker
    Jan 17 at 22:27
3

From the link posted in the answer above it specifically states NOT to put the Private folder within docroot:

"add the url path to your private directory. It must exist outside of your web root directory and be an absolute path, for example /var/www/html/example.org/private with web root in/var/www/html/example.org/web or /home/username/example.org/private with web root in /home/username/example.org/web. So it should look like:

$settings['file_private_path'] = $app_root . '/../private'; "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.