Here is something mysterious: I am running a Drupal 9 installation on Windows WSL2 with Docker and DDEV, which works great. Now I have decided to set up a private files directory for images. I have done so, following all the instructions (e.g. private directory at the same level as the web directory). I did the same for a live server on cPanel. Then I created a simple test entity with only an image field, specifying that uploaded images were to go into the private directory.
The cPanel server version works exactly as expected — when I created a new image entity, the image went right into the private directory. So I’m pretty sure I have the procedure down correctly.
But the DDEV version does mysterious things. When I create a new image entity, everything goes just fine, the entity is created, I can see the image, etc. But the private directory is empty. Furthermore, if I search the entire WSL2 file system, the image file is nowhere to be found. And yet it is there, somewhere. I have created several such entities, and now have a nice list of about ten image files, all of which display nicely. And all of which are nowhere to be found in the WSL2 file system (at least through a filename search), and certainly not in the specified private directory.
So where are they?? Any ideas about this mystery? 🙂
Thanks!
P.S. There is only one clue I have noticed. The first time, I accidentally specified my private files directory to be below the web directory. Then it worked correctly, and I saw the uploaded image file. But as you know, the instructions are that it should NOT be inside the web directory, but rather outside of it, not HTTPS accessible. So maybe DDEV has some kind of unusual characteristic that makes it a problem to have the private directory outside of the web directory.
3
Answers
The question was answered by the comments of rfay to the original post.
To configure the private file system with Drupal 8.9 in ddev do this:
Create the private folder in /var/www/html, for example /var/www/html/privatefiles (not above html, it will be removed at ddev restart)
Make sure the folder is writable by the web server, like the web folder
Set the $settings[‘file_private_path’] value in your settings.php
Clear caches and Drupal will generate the appropriate .htaccess file in the folder you specified
Confirm no File system or Private files directory errors found at admin/report/status. Settings can be viewed at admin/config/media/file-system.
You can simply add the following lines to your distributed
settings.php
to only take effect inside DDEV to create and set the private files dir: