0

I'm new in the world of Django. I've been working on setting up WSGI to serve my Django project. It is working fine on my personal machine but on the server I'm having a hard time to setup.

I'm using logging in Django. But it is giving 'permission denied' error. But when I place all my log files in the '/tmp' folder, it works fine. Similar issue is with the 'db.sqlite3' file (that is my DB file which the Django uses).

Please help me out in resolving the issue.

Following information may be useful to help me out :

OS : CentOS 7 Python : 2.7.5 Apache : 2.4.6 MOD_WSGI : 3.4

Following is the WSGI's error_log:

[Wed Aug 05 01:53:31.661156 2015] [:error] [pid 32177] [remote 192.168.40.142:184] Traceback (most recent call last):
[Wed Aug 05 01:53:31.661192 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/var/www/html/portals/wsgi.py", line 18, in <module>
[Wed Aug 05 01:53:31.661254 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     application = get_wsgi_application()
[Wed Aug 05 01:53:31.661274 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/var/www/html/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Aug 05 01:53:31.661313 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     django.setup()
[Wed Aug 05 01:53:31.661330 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/var/www/html/venv/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
[Wed Aug 05 01:53:31.661361 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Wed Aug 05 01:53:31.661378 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/var/www/html/venv/lib/python2.7/site-packages/django/utils/log.py", line 86, in configure_logging
[Wed Aug 05 01:53:31.661451 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     logging_config_func(logging_settings)
[Wed Aug 05 01:53:31.661483 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/usr/lib64/python2.7/logging/config.py", line 803, in dictConfig
[Wed Aug 05 01:53:31.661519 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     dictConfigClass(config).configure()
[Wed Aug 05 01:53:31.661537 2015] [:error] [pid 32177] [remote 192.168.40.142:184]   File "/usr/lib64/python2.7/logging/config.py", line 585, in configure
[Wed Aug 05 01:53:31.661584 2015] [:error] [pid 32177] [remote 192.168.40.142:184]     '%r: %s' % (name, e))
[Wed Aug 05 01:53:31.661643 2015] [:error] [pid 32177] [remote 192.168.40.142:184] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/var/www/html/portals/logs/debug.log'
Abhay
  • 46
  • 1
  • 9
  • Make sure apache can write to the directory where the log is. It will need to be owned / writeable by the apache process (ususally `www_data` or `apache` on the common distros) – arco444 Aug 04 '15 at 12:54
  • You need to do something like: `chown -R www-data:www-data /var/myapp/` - that will set the file ownership of your files to the `www-data` group and user. – henrikstroem Aug 04 '15 at 13:23
  • How did you setup mod_wsgi (daemon mode, run mod_wsgi as user)? Do you use virtual hosts, or only one site? – het.oosten Aug 04 '15 at 13:42
  • I only use one site. I have setup mod_wsgi in the daemon mode. Can someone please throw light on 'www-data' user and user-group? – Abhay Aug 05 '15 at 06:43

1 Answers1

0

You need to fix permissions with the chmod command, like this:

chmod 775 /var/www/html/portals/logs/debug.log
chown username:apache /var/www/html/portals/logs/debug.log

If group is www-data,change apache to www-data

If the security not matters.You can try

chmod 777 /var/www/html/portals/logs/debug.log
itzMEonTV
  • 19,851
  • 4
  • 39
  • 49
  • Thanks @itzmeontv but I tried all of this. None of the 3 approaches seem to be working. I'm really really pissed of now as I am unable to understand that when I have given 777 permission to the damn 'debug.log' file then how in the world it can say 'permission denied' in any case?? :-/ – Abhay Aug 05 '15 at 06:42
  • Please show here `ls -l /var/www/html/portals/logs/debug.log` – itzMEonTV Aug 05 '15 at 10:03
  • SELinux may still be blocking you if enabled. – Graham Dumpleton Aug 05 '15 at 11:25