I'm running a django app through fcgi on my school's shared hosting system. Everything works initially (standard start page shows when I view the directory with index.fcgi) but when I add a module and try to import, I get the following error. The same code works when I run on my local machine.
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: Traceback (most recent call last):
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 558, in run
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: protocolStatus, appStatus = self.server.handler(self)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 1116, in handler
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: result = self.application(environ, start_response)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: response = self.get_response(request)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 134, in get_response
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return self.handle_uncaught_exception(request, resolver, exc_info)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 154, in handle_uncaught_exception
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return debug.technical_500_response(request, *exc_info)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/views/debug.py", line 40, in technical_500_response
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: html = reporter.get_traceback_html()
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/views/debug.py", line 114, in get_traceback_html
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return t.render(c)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 178, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return self.nodelist.render(context)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: bits.append(self.render_node(node, context))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 81, in render_node
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: raise wrapped
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: TemplateSyntaxError: Caught an exception while rendering: No module named students
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: Original Traceback (most recent call last):
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: result = node.render(context)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 87, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: output = force_unicode(self.filter_expression.resolve(context))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 572, in resolve
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: new_obj = func(obj, *arg_vals)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/template/defaultfilters.py", line 687, in date
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return format(value, arg)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 269, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return df.format(format_string)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 30, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: pieces.append(force_unicode(getattr(self, piece)()))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 175, in r
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return self.format('D, j M Y H:i:s O')
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 30, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: pieces.append(force_unicode(getattr(self, piece)()))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/encoding.py", line 71, in force_unicode
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: s = unicode(s)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/functional.py", line 201, in __unicode_cast
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return self.__func(*self.__args, **self.__kw)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 62, in ugettext
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return real_ugettext(message)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 286, in ugettext
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: return do_translate(message, 'ugettext')
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 276, in do_translate
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: _default = translation(settings.LANGUAGE_CODE)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 194, in translation
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: default_translation = _fetch(settings.LANGUAGE_CODE)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 180, in _fetch
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: app = import_module(appname)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: __import__(name)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: ImportError: No module named students
Two questions. One, it seems like the same error as this but I can't figure out what to add to my pythonpath. Here's the contents of my index.fcgi. I tried executing
sys.path.insert(0, "/keone/Scripts/django/resume/students")
but that didn't help.
#!/usr/bin/env python
import sys, os, time, threading, django.utils.autoreload
sys.path.insert(0, "/keone/Scripts/django")
os.chdir("/keone/Scripts/django/resume")
os.environ['DJANGO_SETTINGS_MODULE'] = "resume.settings"
def reloader_thread():
while True:
if django.utils.autoreload.code_changed():
os._exit(3)
time.sleep(1)
t = threading.Thread(target=reloader_thread)
t.daemon = True
t.start()
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Two, how do I change the fcgi file to close standard output and standard error and reopen them to a different file? I had to get a sysadmin to get a snippet out of the master log, and I can't count on this consistently.
Thanks for your help!
Does sys.path.insert(0, "/keone/Scripts/django/resume/") work? I assume everything is working fine in a runserver.
You can pass in outlog and errlog to runfastcgi. http://code.djangoproject.com/browser/django/trunk/django/core/servers/fastcgi.py?rev=10345#L21
Related
I'm trying to access a Django application using apache and I'm getting Internal Server Error. I've opened the logs to see what is going on and I found this:
[Thu Jun 23 03:10:03 2016] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jun 23 03:10:03 2016] [notice] Digest: generating secret for digest authentication ...
[Thu Jun 23 03:10:03 2016] [notice] Digest: done
[Thu Jun 23 03:10:03 2016] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Target WSGI script '/home/TaskManagement/teamwork/wsgi.py' cannot be loaded as Python module.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Exception occurred processing WSGI script '/home/TaskManagement/teamwork/wsgi.py'.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] Traceback (most recent call last):
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/TaskManagement/teamwork/wsgi.py", line 15, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.core.wsgi import get_wsgi_application
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/__init__.py", line 1, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.version import get_version
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/version.py", line 7, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.lru_cache import lru_cache
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/lru_cache.py", line 28
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] fasttypes = {int, str, frozenset, type(None)},
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] ^
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] SyntaxError: invalid syntax
I'm using python 3.4, Django 1.9, apache 2.2.
and here is my apache configuration:
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias / /home/TaskManagement/teamwork/wsgi.py process-group=hrm.jodod.info
WSGIDaemonProcess hrm.jodod.info python-path=/home/TaskManagement:/home/py3venv/lib/python3.4/site-packages
WSGIProcessGroup hrm.jodod.info
Alias /robots.txt /home/TaskManagement/robots.txt
Alias /favicon.ico /home/TaskManagement/favicon.ico
Alias /static/ /home/TaskManagement/static/
<Directory /path/to/mysite.com/static>
Order deny,allow
Allow from all
</Directory>
<Directory /home/TaskManagement/teamwork>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
and here is my wsgi.py file:
import os
import sys
sys.path.append('/home/TaskManagement')
sys.path.append('/home/TaskManagement/teamwork')
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
application = get_wsgi_application()
Can anybody figure out what am I doing wrong?
Python/2.6.6 configured -- resuming normal operations
Looks like your mod_wsgi is compiled against Python 2.6.6 and you're trying to run Python3 code with it. The Set syntax you are seeing in the error appeared in Py3. Recompile mod_wsgi and try again.
Your wsgi.py line 9 has to be
os.environ["DJANGO_SETTINGS_MODULE"] = "teamwork.settings"
if the directory it's stored is called teamwork (your project's name)
also in your manage.py it has to be "teamwork.settings"
I am using Django 1.6 and Apache for my website, at first the server worked well, I could successfully go to my web pages, but just after I run:
git reset --hard HEAD^
in my /var/www/html/mysite repository, it showed Internal Server Error in the browser and I got this in the error log:
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Create interpreter 'www.XXX.XXX|'.
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Adding '/var/www/html/mysite' to path.
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Adding '/usr/local/lib/python2.7/site-packages' to path.
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] mod_wsgi (pid=15479): Exception occurred processing WSGI script '/var/www/html/mysite/mysite/wsgi.py'.
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] Traceback (most recent call last):
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self.load_middleware()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self._setup(name)
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 50, in _setup
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self._configure_logging()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 80, in _configure_logging
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] logging_config_func(self.LOGGING)
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/logging/config.py", line 794, in dictConfig
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] dictConfigClass(config).configure()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/logging/config.py", line 576, in configure
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] '%r: %s' % (name, e))
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/debug.log'
I saw it was "Permission denied", so I've run:
sudo chown -R www-data:www-data mysite
And also:
sudo chmod -R 755 mysite
But it is still not working, I even changed the persmission to 777 for the whole html directory but it was no use.
I don't understand why there came out an permission error, is there anything related to the git command that I run?
PS : I didn't mentioned at all the /debug.log in my settings.py, I wrote:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'debug.log',
},
},
'loggers': {
'django.request': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
The problem is in your settings.py in the file, in the section that controls logging.
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/debug.log'
While you can certainly write to /debug.log with proper permissions, it's an unlikely location. Please choose a more appropriate one. You can do that by changing this line:
'filename': 'debug.log',
in your logging setup. Be sure to give a full path eg /tmp/debug.log or /var/log/httpd/debug.log
If you really want to write to that file do
sudo touch /debug.log
sudo chown www-data:www-data /debug.log
and reload mod wsgi
I got the following setup for my django server running on debian:
Apache Config:
<VirtualHost *:8083>
ServerAdmin <mail>
ServerName <ip>
ServerAlias http://<ip>
<Directory /var/www/backend/api/backend/ >
AllowOverride All
Require all granted
Allow from all
</Directory>
WSGIScriptAlias / /var/www/backend/api/backend/apache/django.wsgi
ErrorLog /var/www/backend/api/backend/error.log
</VirtualHost>
Backendfolder with access rights:
drwxrwxr-x 7 www-data www-data 4096 Okt 26 16:23 .
drwxrwxr-x 3 www-data www-data 4096 Sep 29 19:58 ..
drwxrwxr-x 2 www-data www-data 4096 Sep 29 21:47 apache
drwxrwxr-x 9 www-data www-data 4096 Sep 30 16:13 archiv_backend
-rwxrwxr-x 1 www-data www-data 72704 Sep 29 21:56 archiv.db
-rwxrwxrwx 1 www-data www-data 1927 Okt 5 16:59 archiv.log
-rwxrwxr-x 1 www-data www-data 941822 Sep 29 21:26 archiv.log.2015-09-29
-rwxrwxr-x 1 www-data www-data 489231 Sep 30 15:07 archiv.log.2015-09-30
-rwxrwxr-x 1 www-data www-data 3805 Okt 2 23:14 archiv.log.2015-10-02
-rwxrwxr-x 1 www-data www-data 15555 Okt 3 22:40 archiv.log.2015-10-03
drwxrwxr-x 2 www-data www-data 4096 Sep 30 15:56 backend
-rwxrwxr-x 1 www-data www-data 255417 Okt 26 17:17 error.log
drwxrwxr-x 8 www-data www-data 4096 Okt 26 16:29 .git
drwxrwxr-x 3 www-data www-data 4096 Sep 29 19:58 .idea
-rwxrwxr-x 1 www-data www-data 250 Sep 29 19:58 manage.py
-rwxrwxr-x 1 www-data www-data 182 Sep 30 15:25 requirements.txt
-rwxrwxr-x 1 www-data www-data 0 Okt 26 16:29 wsgi.py
In the apache2.conf I added:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
<Directory /var/www/backend/api/backend/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
When I send a request to the server on port 8083 I always see the following error in the error.log:
[Mon Oct 26 16:23:28.171069 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] mod_wsgi (pid=13469): Target WSGI script '/var/www/backend/api/backend/apache/django.wsgi' cannot be loaded as Python module.
[Mon Oct 26 16:23:28.171113 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] mod_wsgi (pid=13469): Exception occurred processing WSGI script '/var/www/backend/api/backend/apache/django.wsgi'.
[Mon Oct 26 16:23:28.171142 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] Traceback (most recent call last):
[Mon Oct 26 16:23:28.171169 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/var/www/backend/api/backend/apache/django.wsgi", line 16, in <module>
[Mon Oct 26 16:23:28.171208 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] application = get_wsgi_application()
[Mon Oct 26 16:23:28.171278 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Oct 26 16:23:28.171381 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] django.setup()
[Mon Oct 26 16:23:28.171418 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup
[Mon Oct 26 16:23:28.171443 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Oct 26 16:23:28.171478 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 86, in configure_logging
[Mon Oct 26 16:23:28.171513 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] logging_config_func(logging_settings)
[Mon Oct 26 16:23:28.171568 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
[Mon Oct 26 16:23:28.171591 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] dictConfigClass(config).configure()
[Mon Oct 26 16:23:28.171601 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] File "/usr/lib/python2.7/logging/config.py", line 576, in configure
[Mon Oct 26 16:23:28.171615 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] '%r: %s' % (name, e))
[Mon Oct 26 16:23:28.171654 2015] [wsgi:error] [pid 13469:tid 139695967143680] [client <ip>:56892] ValueError: Unable to configure handler 'logfile': [Errno 13] Permission denied: '/archiv.log'
[Mon Oct 26 16:23:28.315954 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] mod_wsgi (pid=13469): Target WSGI script '/var/www/backend/api/backend/apache/django.wsgi' cannot be loaded as Python module., referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.315978 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] mod_wsgi (pid=13469): Exception occurred processing WSGI script '/var/www/backend/api/backend/apache/django.wsgi'., referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.315995 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] Traceback (most recent call last):, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316013 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/var/www/backend/api/backend/apache/django.wsgi", line 16, in <module>, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316034 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] application = get_wsgi_application(), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316124 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316192 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] django.setup(), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316207 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316300 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316336 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 86, in configure_logging, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316357 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] logging_config_func(logging_settings), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316367 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316429 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] dictConfigClass(config).configure(), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316485 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] File "/usr/lib/python2.7/logging/config.py", line 576, in configure, referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316523 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] '%r: %s' % (name, e)), referer: http://<ip>:8083/
[Mon Oct 26 16:23:28.316548 2015] [wsgi:error] [pid 13469:tid 139695958750976] [client <ip>:56894] ValueError: Unable to configure handler 'logfile': [Errno 13] Permission denied: '/archiv.log', referer: http://<ip>:8083/
Here is my WSGI file:
import os
import sys
path = '/var/www/backend/api/backend/'
if path not in sys.path:
sys.path.insert(0, '/var/www/backend/api/backend/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'backend.settings'
os.environ['ARCHIV_ENVIRONMENT'] = 'production'
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
One solution I found was to chown or chgrp the folder or the log file in the /var/www/ directory. As you can see, all files there are now owned and for grp www-data which should be used by wsgi.
But I still get the error. I didn't forget to restart apache.
According to the error messages, it's trying to write to /archiv.log. Look closely at the logging information in settings.py to see why it's trying to write to the root directory.
I have been trying to deploy my Django application on ubuntu 14.04 with the installed packages which are:
django 1.4.15
apache 2.4
python 2.7
mod_wsgi 3.4 (there is one compiled as mod_wsig.so-2.7 which is the one I use)
on my apache config I have this fields:
# Modules
LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so
LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so-2.7
LoadModule setenvif_module /usr/lib/apache2/modules/mod_setenvif.so
LoadModule authn_core_module /usr/lib/apache2/modules/mod_authn_core.so
LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so
...
<Directory />
Options FollowSymLinks
AllowOverride None
AuthType none
Require all granted
</Directory>
...
# And finally the app config.
WSGIPythonHome /home/web/.virtualenvs/web
WSGIPythonPath /PATH/TO/MYSITE:/home/web/.virtualenvs/web/lib/python2.7/site-packages
WSGIScriptAlias / "/PATH/TO/wsgi.py"
Everything seems to be fine until I try to import one of the local modules in my system. By this I mean, the wsgi.py script runs no problem and then the django settings.py start running, in the settings I have this code:
from MYSITE.environments.prod_settings import *
environments is a module with it's own __init__.py file and all. but when it reaches that line it can't import.
The other part is that the site runs perfectly when I run ./manage.py runserver and the info in the sys.path is just the same!
I am just out of ideas on why apache wsgi will not let me import that python module.
Here is the latest logs:
[Fri Nov 28 18:07:06.222374 2014] [core:notice] [pid 3639:tid 140258688976768] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 28 18:07:09.322057 2014] [:error] [pid 3642:tid 140258619721472] /home/web/.virtualenvs/web <--- printed the sys.prefix
[Fri Nov 28 18:07:09.673877 2014] [:error] [pid 3642:tid 140258619721472] 2014-11-28 18:07:09,670 (3642/MainThread) newrelic ERROR - Falling back to stderr logging as unable to create log file '/var/log/newrelic/newrelic-python-agent.log'.
[Fri Nov 28 18:07:09.673930 2014] [:error] [pid 3642:tid 140258619721472] Traceback (most recent call last):
[Fri Nov 28 18:07:09.673941 2014] [:error] [pid 3642:tid 140258619721472] File "/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26/newrelic/common/log_file.py", line 79, in initialize_logging
[Fri Nov 28 18:07:09.673950 2014] [:error] [pid 3642:tid 140258619721472] _initialize_file_logging(log_file, log_level)
[Fri Nov 28 18:07:09.673959 2014] [:error] [pid 3642:tid 140258619721472] File "/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26/newrelic/common/log_file.py", line 51, in _initialize_file_logging
[Fri Nov 28 18:07:09.673969 2014] [:error] [pid 3642:tid 140258619721472] handler = logging.FileHandler(log_file)
[Fri Nov 28 18:07:09.673977 2014] [:error] [pid 3642:tid 140258619721472] File "/usr/lib/python2.7/logging/__init__.py", line 903, in __init__
[Fri Nov 28 18:07:09.673985 2014] [:error] [pid 3642:tid 140258619721472] StreamHandler.__init__(self, self._open())
[Fri Nov 28 18:07:09.673993 2014] [:error] [pid 3642:tid 140258619721472] File "/usr/lib/python2.7/logging/__init__.py", line 928, in _open
[Fri Nov 28 18:07:09.674001 2014] [:error] [pid 3642:tid 140258619721472] stream = open(self.baseFilename, self.mode)
[Fri Nov 28 18:07:09.674009 2014] [:error] [pid 3642:tid 140258619721472] IOError: [Errno 13] Permission denied: '/var/log/newrelic/newrelic-python-agent.log'
[Fri Nov 28 18:07:09.985905 2014] [:error] [pid 3642:tid 140258619721472] No module named wizzytest2 <---- My module name
After the module error the logs errors are about problems with database connections in general. This happens because in the wizzytest2 module I have settings overrides so that is expected.
[Sat Nov 29 21:37:44.923879 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web' <-- python home
[Sat Nov 29 21:37:44.924177 2014] [:error] [pid 6097:tid 140297485195008] ['/home/web/.virtualenvs/web/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924230 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE/mysite',
[Sat Nov 29 21:37:44.924256 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/src/python-itunes',
[Sat Nov 29 21:37:44.924287 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7',
[Sat Nov 29 21:37:44.924312 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/plat-x86_64-linux-gnu',
[Sat Nov 29 21:37:44.924342 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-tk',
[Sat Nov 29 21:37:44.924366 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-old',
[Sat Nov 29 21:37:44.924395 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-dynload',
[Sat Nov 29 21:37:44.924419 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7',
[Sat Nov 29 21:37:44.924449 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7/plat-x86_64-linux-gnu',
[Sat Nov 29 21:37:44.924483 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7/lib-tk',
[Sat Nov 29 21:37:44.924557 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/local/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924583 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26',
[Sat Nov 29 21:37:44.924615 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924641 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/site-packages/newrelic-2.28.0.26',
[Sat Nov 29 21:37:44.924663 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE',
[Sat Nov 29 21:37:44.924695 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE/mysite']
[Sat Nov 29 21:37:45.474168 2014] [:error] [pid 6097:tid 140297485195008] No module named wizzytest2
Just added the python path too so it's easier to debug. I also fixed the newrelic issue but that doesn't makes any difference on the settings file wizzytest2 been found or not.
Now with your logs I think the trouble is evident:
IOError: [Errno 13] Permission denied: '/var/log/newrelic/newrelic-python-agent.log/'
The user which launches your application doesn't have the right to write in '/var/log/newrelic/newrelic-python-agent.log'.
Maybe chmod -R +w '/var/log/newrelic/' can help you. But in fact, you should place the user which launch your app in an appropriate group which can write logs.
Note:
You should use uWSGI or Gunicorn for control you app and only use apache as frontend.
At the end this was an issue with permissions on the overriding settings file I wanted to import, at the end I just needed to do a chown web:web to the file and a chmod.
I am trying to deploy my project using mod_wsgi. Unfortunately I get:
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Exception in WSGI handler:
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Traceback (most recent call last):
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/home/project/project/wsgi/project.wsgi", line 26, in application
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] return handler(environ, start_response)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/wsgi.py", line 230, in __call__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] self.load_middleware()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/base.py", line 33, in load_middleware
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/functional.py", line 276, in __getattr__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] self._setup()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 40, in _setup
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] self._wrapped = Settings(settings_module)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 73, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/importlib.py", line 35, in import_module
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] __import__(name)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/home/project/project/__init__.py", line 7, in <module>
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] logging.config.fileConfig(settings.LOG_CONFIG)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/logging/config.py", line 84, in fileConfig
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] handlers = _install_handlers(cp, formatters)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/logging/config.py", line 152, in _install_handlers
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] h = apply(klass, args)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/logging/handlers.py", line 109, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] BaseRotatingHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/logging/handlers.py", line 61, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] logging.FileHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] File "/usr/lib/python2.5/logging/__init__.py", line 772, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] stream = open(filename, mode)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] IOError: [Errno 13] Permission denied: 'project.log'
I have an entry for my project inside /etc/apache2/sites-enabled/:
SetEnv app_settings project.config.production
WSGIDaemonProcess project user=project group=project threads=1 processes=1 home=/home/project/project python-path=/home/project
<VirtualHost *>
ServerName project.internal
WSGIScriptAlias / /home/project/project/wsgi/project.wsgi
WSGIProcessGroup %{GLOBAL}
</VirtualHost>
My logs should be stored inside the project directory. I have investigated it a little and just before project.log is supposed to be opened I run os.getcwd(), which returned /. Can anyone tell me, what I might have misconfigured that this happens?
This is not much of an answer, but I set my site up to only use absolute pathnames, pulling in the base paths from settings.py. You can have variables in settings.py that aren't official Django settings names, and as long as you name them using ALLCAPS_WITH_UNDERSCORES style, it will let you import those with import settings.
IIRC, daemons in general should use absolute pathnames. Apparently, using relative pathnames can be a security hole.
It's not about paths, it's about permissions.
The apache user is trying to create that log file, so you should give it write permissions on that directory.