I am running nginx, mariadb and php8.2-fpm on my WSL2 Ubuntu server successfully, all running as user www-data just fine, however, I cannot upload files from the web interface. When I attempt to, the nginx error log records the following:

2023/05/03 09:27:46 [error] 1339#1339: *1 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Drupal\Core\File\Exception\FileWriteException: "The destination directory 'public://2023-05' is not writable" at /var/www/html/repo/web/core/modules/media_library/src/Form/FileUploadForm.php line 332" while reading response header from upstream, client: ::1, server: localhost, request: "POST /media-library?media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bimage%5D=image&media_library_selected_type=image&media_library_remaining=1&media_library_opener_parameters%5Bfield_widget_id%5D=field_image&media_library_opener_parameters%5Bentity_type_id%5D=node&media_library_opener_parameters%5Bbundle%5D=article&media_library_opener_parameters%5Bfield_name%5D=field_image&media_library_opener_parameters%5Bentity_id%5D=144&media_library_opener_parameters%5Brevision_id%5D=741&hash=q_RtKmTw2wyucMR1nnKCucBF2P1b1crtsxJDMyk7fW8&ajax_form=1&_wrapper_format=drupal_ajax HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.2-fpm.sock:", host: "localhost", referrer: "http://localhost/"

Thinking that the issue may be with nginx and php8.2-fpm, I've also successfully configured apache to run with php8.2 and similarly get this error inside of Apache's error log:

[Wed May 03 09:28:32.068299 2023] [php:notice] [pid 1195] [client ::1:59860] Uncaught PHP Exception Drupal\Core\File\Exception\FileWriteException: "The destination directory 'public://2023-05' is not writable" at /var/www/html/repo/web/core/modules/media_library/src/Form/FileUploadForm.php line 332, referer: http://localhost:8080/

nginx, mariadb and php-fpm are all running as www-data and the folder permissions are all set to www-data:www-data (chown -R www-data:www-data ./) with full access to the files (chmod -R 777 ./).

I've also added the following to my /etc/wsl.conf file:

enable = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = false

PHP is still unable to write to write files. Any ideas on how to deal with write permissions on WSL 2 instances of Ubuntu?

  • 1
    So it's complaining about a directory called public://2023-05? It appears despite your best efforts the directory being used by FileUploadForm.php does not have the correct permissions. Provide the relevant information for your Drupal installation.
    – Ramhound
    May 3 at 15:00

1 Answer 1


The Drupal post The directory sites/default/files exists but is not writable and could not be made writable might be relevant here.

The answer by Ankit Agrawal says this:

One way that may work for you is changing the group and make it group writable as below:

chgrp www-data sites/default/files
chmod g+w sites/default/files

As per drupal docs the correct permission for all files is 644, and for directories is 755.

Also check this: What are the recommended directory permissions?

Replace sites/default/files with your folder.

  • Thanks harrymc, I unsuccessfully applied your recommendation, but I don't think it really changed anything. I am running nginx and php8.2-fpm , both, as www-data , and all of my folders have www-data:www-data as user/group owners. (UID: 1000) . I have also added www-data into my personal user group, as well as adding my personal user id into the www-data group. Finally, I have given www-data:www-data 7777 ownership (chown) to the entire web directory, recursively. This is Ubuntu running under WSL2 (Windows 11) , Composer is able to run and download files, May 10 at 17:21
  • Reading docs link in my answer and its comments, it seems like the permissions need to be very exact. Try it.
    – harrymc
    May 10 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .