Apache WSGI permission error using django logging on production server
After reading up on SELinux, I have figured out the solution for this permission error. And I hope that it will help the others who have encountered similar situation when deploying on production server under RHEL linux.
Basically running the command ls -Z shows the following
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 log
the folder is labelled with httpd_sys_content_t which does not allow httpd to have write access the the folder. Therefore we need to change this label to httpd_sys_rw_content_t
Firstly, we need to add an entry to the fcontext to inform SELinux what is the default label for files, that will be created, in this folder.
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/directory(/.*)?"
This will add an entry to the fcontext file (/etc/selinux/targeted/contexts/files/file_contexts.local)
Next we need to update all the labels of the files in the folder using restorecon.
sudo restorecon -R -v /path/to/directory
And now the permission error related to the django logging will be gone from the httpd error_log =)