Making files writeable by web server on CentOS

To make a file writeable by the web server user on CentOS you need to set both the traditional permissions and the SELinux security context for that file.

The web server user in CentOS is called apache.

chgrp apache /var/www/my-file
chmod g+rw /var/www/my-file
semanage fcontext -a -t httpd_sys_rw_content_t /var/www/my-file
restorecon -R -F /var/www/my-file

Relative paths from your current directory are acceptable for chgrp and chmod, but you have to use the full absolute path for the SELinux commands.

Posted