I've just spent an hour and a half wrestling with the following error and a similar one regarding settings.php:
"The directory sites/default/files does not exist. An automated attempt to create this directory failed, possibly due to a permissions problem" despite having all the correct file system permissions set.
As my resolution does not seem to be documented here, I thought I'd share.
My problem relates to Security Enhanced Linux (SELinux). With SELinux, the apache daemon is extensively locked down as to what it is and isn't permitted to do (eg. file system accesses outside of /var/www, outbound network connections are both disabled by default).
Additionally all content in /var/www/html is deemed read-only by default, irrespective of what the file permissions may think about this. In order to get the Drupal install to work, you need to tell SELinux that it is ok for the apache daemon to create directories in the sites/default/ directory as well as edit settings.php.
This is achieved by changing the file label for those as follows (file labels can be displayed using ls -Z):
chcon -t httpd_sys_content_rw_t sites/default/ chcon -t httpd_sys_content_rw_t sites/default/settings.php
(commands run from root of Drupal install - root access is required to change file labels)
If I run into any more gotchas getting Drupal running on SELinux I'll add it here
Comments
Thanks
Thank you for posting this. I bet other people have run into very similar issues.
Thanks!
Awesome! this saved my behind!
I'm on Fedora 14 and I was having problems when I was using Drush to install Drupal and modules. Modules would download and I could enable/disable them using Drush, but they would never show in the website. Never show in the Modules list. using this saved me.
Here's a slight variation for others:
Where folder is the folder you want to apply to.
this is using a label I found based on a folder I created manually. Not sure if I need to include the rw_t in the label, but this seems to work.
Jarod Smith
JarodMS
Watch for SELinux relabelling
chcon is only a temporary solution. To avoid losing your settings when SELinux relabels the filesystem, I recommend using:
semanage fcontext -a -t httpd_sys_content_rw_t "/sites/default/files(/.*)?"
More information in the SELinux documentation, or if you want to see this already setup, checkout out the Drupal VM project.
Thank you
Thank you for this short and useful post. I have been struggling with this for more than half an hour (and it would have been more if I didn't find this)
Composer patches?
I have a similar issue applying patches via composer. Specifically, I have a patch that applies without error on my local, but on my server (where SELinux is enabled) the patch fails to apply. Anyone run into something similar?