'Drupal - The directory sites/default/files exists but is not writable and could not be made writable

When I try to add "Public file system path" and "Private file system path" in Administration > Configuration > Media > File System in my drupal site, I get "The directory sites/default/files exists but is not writable and could not be made writable" Error. But it is working fine in localhost.

The permission for the folders is 755, I changed it to 777. But still it didnt work.

I also changed the owner following some blogs using: chown -R apache:apache private

But it didnt help either.

Please Help. Thanks in advance.

enter image description here



Solution 1:[1]

Try to replace .htaccess in sites/default/files with the original one or

try to remove .htaccess in sites/default/files or

try to change .htaccess in sites/default/files from Options None Options +FollowSymLinks to #Options None #Options +FollowSymLinks

You could try same with .htaccess in Drupal root

Solution 2:[2]

Probably you need to run restorecon on the directory for eg:

restorecon -rv default/

Solution 3:[3]

chmod -R 777 sites/default/files/

^ worked for me, however I had no private file system path.

Solution 4:[4]

I am too late for this answer but may help someone who searches for it.

If SELinux security is enabled and there is not a "rw" in the context for the files/ directory it will not be writable no matter which group, user, or Unix permissions are granted.

To see these "hidden" settings:

ls -laZ sites/default

drwxr-sr-x. apache www unconfined_u:object_r:httpd_sys_content_t:s0 .
drwxr-xr-x. apache www unconfined_u:object_r:httpd_sys_content_t:s0 ..
-rwxr-sr-x. apache www unconfined_u:object_r:httpd_sys_content_t:s0         default.settings.php
drwxrwsr-x. apache www unconfined_u:object_r:httpd_sys_content_t:s0 files
-rwxr-sr-x. apache www unconfined_u:object_r:httpd_sys_rw_content_t:s0 settings.php

To change the settings on files/ so it is writable:

sudo chcon -R -t httpd_sys_rw_content_t files

When the install is done reset the context using the same command with the original "http_sys_content_t" context.

FYI - This command will also be necessary to enable writes when installing themes under the "all" directory.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Dhruv Tyagi
Solution 3 Bill Shannon
Solution 4 jayaprakash R