Permission denied mod_wsgi in CentOS

Published 2016-01-25

If you ever setup python with Apache for the first time, you'll definitely encounter a bunch of problems. I'm currently writing a post about all the steps I took to do it but one of the things that really bugged me out is the permission denied mod_wsgi problem. It was supposedly the last problem I'll run into after a seemingly endless string of problems I encountered. Take note that at the point I encountered this problem, I'm almost ready to give up setting up Python+Apache. Luckily, I'm a stubborn bastard. At any rate, the problem is traced some linux distributions' restriction on standard Apache runtime such that the directory is not readable to others. Since the user for Apache child processes with mod_wsgi not have permission to the directory, mod_wsgi will would not be able to connect to the sockets. To solve this, we need to add some directive in the Apache configuration.

In my case, I'm using CentOS which is the community version of RedHat. That means I have to add the following on my Apache configuration (/etc/httpd/conf/httpd.conf).

WSGISocketPrefix /var/run/wsgi

More details at the MOD_WSGI Wiki page in the link below. It's beautifully explained there. https://code.google.com/p/modwsgi/wiki/ConfigurationIssues