slaughterize
slaughterize

Reputation: 734

Apache mod_wsgi: PermissionError when trying to access a page

Trying to get Django running on this Apache box, using Python 3.3

httpd starts without fault but as soon as I try to access localhost, I am thrown a 500 error. The Apache logs say this:

[Wed Aug 20 13:50:24 2014] [error] [client 127.0.0.1] PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.3/site-packages/django/__init__.py'
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1] mod_wsgi (pid=691): Target WSGI script '/var/www/tabstat/projet_tabstat/wsgi.py' cannot be loaded as Python module.
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1] mod_wsgi (pid=691): Exception occurred processing WSGI script '/var/www/tabstat/projet_tabstat/wsgi.py'.
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "/var/www/tabstat/projet_tabstat/wsgi.py", line 13, in <module>
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]     from django.core.wsgi import get_wsgi_application
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 1022, in load_module
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 1003, in load_module
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 853, in _load_module
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 977, in get_code
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1]   File "<frozen importlib._bootstrap>", line 1031, in get_data
[Wed Aug 20 13:50:26 2014] [error] [client 127.0.0.1] PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.3/site-packages/django/__init__.py'

I tried chmod 777 __init__.py but it didn't change anything. Wondering what could cause such an error...

Upvotes: 1

Views: 806

Answers (2)

iDevPy
iDevPy

Reputation: 601

Instead of disabling selinux run this:

restorecon -R /path/to/your/project/
restorecon -R /path/to/python/site-packages/
chcon -u system_u  /path/to/your/project/ -R 
chcon -u system_u  /path/to/python/site-packages/ -R
chown apache.apache /path/to/your/project/ -R
chown apache.apache /path/to/python/site-packages/ -R

# Remember to restart apache
systemctl restart httpd.service

Upvotes: 1

slaughterize
slaughterize

Reputation: 734

I found out it was SELinux not trusting the file for some reason.

Upvotes: 0

Related Questions