PHP is_writable() function always returns false for a writable directory

陌路散爱 提交于 2019-12-03 10:45:44

After much head-scratching, it transpired that SELinux was preventing the directory from being written to. I found a good tutorial that explains what's going on. I was able to fix it by running this command:

sudo chcon -R -t httpd_sys_rw_content_t tmp
jhl

in CentOS 6 above should be SELinux enable enforcing

setenforce Permissive

check the status

sestatus

refer to https://wiki.centos.org/HowTos/SELinux

to write to a directory you also need execute permissions to the dirs above.

namei -l /var/www/html/limesurvey/tmp

should show which step you do not have the correct permissions for.

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp

Taken directly from the Symfony2 installation guide, this solves the problem with cache write access sharing between Apache and CLI tools. This might work for your tmp directory as well.

is_writable by default only checks on the user, not the group. So even if you group is matching and has permissions is_writable will return false. To relax this check you will need to set

safe_mode_gid = On

in the PHP config or change the user accordingly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!