I tried almost for a week, but could not solve this problem, and could not find anything online, that can help me.
I have a multi-domain server with Centos 5.3, and a Django project, I must deploy. I installed python 2.7 to /usr/local/python2.7 for Django 1.3 to work, also installed and enabled mod_wsgi.
Next, what I did, was checkout this project, and create virtualenv in home directory of user, who will own this application. I created wsgi script:
import os
import sys
import site
# path to domain specific virtual environment where python packages will be installed
site.addsitedir('/home/user/domain.com/project/env/lib/python2.7/site-packages')
sys.path.append('/home/user/domain.com/project/')
sys.path.append('/home/user/domain.com/project/application/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
and configured virtualhost.
<VirtualHost \
79.98.31.117:80\
>
ServerName masinis.lt
ServerAlias \
www.masinis.lt
DocumentRoot "/home/user/domain.com/"
WSGIScriptAlias / /home/user/domain.com/project/wsgi_script.wsgi
<Directory "/home/tomas/masinis.lt/liveopenly/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /static/ /home/user/domain.com/project/application/static/
<Directory "/home/user/domain.com/project/application/static/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
What I call project, is actually a folder for virtualenv, instructions and application itself.Application in this case is django project - it has apps, settings and other stuff inside. Also it uses external applications, that are stored in virtualenv folder.
When I try to get to domain.com, I get 500 error. And error_log gives me this:
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] mod_wsgi (pid=11655): Exception occurred processing WSGI script '/home/user/domain.com/project/masinis_lt.wsgi'.
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] Traceback (most recent call last):
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 273, in __call__
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] response = self.get_response(request)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return callback(request, **param_dict)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/application/middleware.py", line 44, in server_error
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return HttpResponseServerError(t.render(Context({'MEDIA_URL': settings.MEDIA_URL})))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 123, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 127, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return compiled_parent._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 127, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return compiled_parent._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 208, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] symlink_if_possible=self.symlink_if_possible)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 493, in _static_file
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(os.path.dirname(new_filepath))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 624, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(head)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 624, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(head)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 626, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] os.mkdir(newdir)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] OSError: [Errno 13] Permission denied: 'static'
When I try to run in development mode (manage.py runserver), everything running, but it looks, like static file are not found, when accessing the page. While server log shows 302 response...
What could be the problem?
Related
this has been troubling me for a while and I cannot find anyone else suffering from the same problem as I am,
I've installed DjangoCMS 3.0.2 and on it, I'm trying to use cmsplugin_contact (I've done the integration and the pages load fine). It seems to work fine in debug mode, where a thank you message is shown on submission. Things go awry the moment I flip the DEBUG flag to False.
The Apache Server gives a '200 Error', which means that the request succeeded, but then something snapped. Examining the traceback in error logs, the CMS tags seem to be the culprit. Apparently, the request object is not being passed and I don't understand why.
Here's the traceback:
File "/home/craft/env/lib/python2.7/django/core/handlers/wsgi.py", line 255, in __call__
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/core/handlers/base.py", line 178, in get_response
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/core/handlers/base.py", line 224, in handle_uncaught_exception
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return callback(request, **param_dict)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/utils/functional.py", line 15, in _curried
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/utils/decorators.py", line 91, in _wrapped_view
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] response = view_func(request, *args, **kwargs)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/views/defaults.py", line 41, in server_error
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return http.HttpResponseServerError(template.render(Context({})))
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 140, in render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return self._render(context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 134, in _render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return self.nodelist.render(context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 830, in render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] bit = self.render_node(node, context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 844, in render_node
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return node.render(context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/classytags/core.py", line 106, in render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return self.render_tag(context, **kwargs)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/sekizai/templatetags/sekizai_tags.py", line 75, in render_tag
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return nodelist.render(context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 830, in render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] bit = self.render_node(node, context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/django/template/base.py", line 844, in render_node
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return node.render(context)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/classytags/core.py", line 106, in render
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] return self.render_tag(context, **kwargs)
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] File "/home/craft/env/lib/python2.7/cms/templatetags/cms_tags.py", line 607, in render_tag
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] context['cms_toolbar_login_error'] = request.GET.get('cms-toolbar-login-error', False) == '1'
[Wed May 28 23:12:17 2014] [error] [client 127.0.0.1] AttributeError: 'NoneType' object has no attribute 'GET'
This problem had also arisen before, when I was not using the cmsplugin_contact module, but was resolved by setting the ALLOWED_HOSTS value and commenting out the TEMPLATE_DEBUG = DEBUG flags. Now, it doesn't seem to work. Any ideas?
I am trying to deploy django application on Linux server with mod_wsgi.
Below are my setting for apache in httpd.conf file -
<VirtualHost 127.0.0.1:8080>
AddDefaultCharset utf-8
LogLevel warn
ServerName myappletrade.com
#WSGIProcessGroup appletrade
WSGIScriptAlias / /var/www/html/appletrade/django.wsgi
DocumentRoot /var/www/html/appletrade
#WSGIDaemonProcess frontend user=vasim group=www
ServerAlias myappletrade.com
CustomLog /var/www/html/appletrade/access_log combined
ErrorLog /var/www/html/appletrade/error_log
<Directory /var/www/html/appletrade>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
django.wsgi file settings -
import os
import sys
sys.path.insert(0, "appletrade")
sys.path.insert(0, "/var/www/html/appletrade/noneapp/env/lib/python2.6/site-packages" )
os.environ['DJANGO_SETTINGS_MODULE'] = 'noneapp.settings.development'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
inside noneapp folder I have setting files for development ,production server.
When I am trying to for myappletrade.com in browser nothing happens.it shows 500 internal server error.
I have checked error log . where it's saying -
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] mod_wsgi (pid=2828): Exception occurred processing WSGI script '/var/www/html/appletrade/django.wsgi'.
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] response = self.get_response(request)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] if resolver.urlconf_module is None:
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] self._urlconf_module = import_module(self.urlconf_name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] __import__(name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/var/www/html/appletrade/noneapp/urls/production.py", line 4, in <module>
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] from noneapp.urls.default import urlpatterns as default_urlpatterns
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/var/www/html/appletrade/noneapp/urls/default.py", line 6, in <module>
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] url(r'^catalog/', include('appletrade.urls', namespace = "catalog")),
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 24, in include
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] urlconf_module = import_module(urlconf_module)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] __import__(name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] ImportError: No module named urls
Please check my configuration setting and Let me know if I am missing something.
Thanks in Advance
You are trying to force Python 2.7 to use Python 2.6 libraries. Your django.wsgi lists the python2.6 site packages in the path, but the errors all list python2.7.
Are you using a virtualenv environment as well? Make sure you're using the python installed in that virtual environment, and not the system version - you will be missing any pip installed packages you have.
Upon further review - you don't have all of your variables defined for mod_wsgi in your VirtualHost configuration, either.
This is the bizarre.
I have a 500.html template below. When I refer to a page that does not exist via the url, my 500.html will show three times (if I try to reload the page repeatedly), then I get the apache Internal Server Error three times. My broser keeps flipping between the two.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Page unavailable</title>
</head>
<body>
<h1>Page unavailable</h1>
<p>Sorry, but the requested page is unavailable due to a
server hiccup.</p>
<p>Our engineers have been notified, so check back later.</p>
</body>
</html>
During the three times I get the Apache Internal Server Error, the error logs say 500.html does not exist - but it does. It pulled it up three times before.
I cleared the cache and tried a different browser with the same results.
Thanks for any help.
EDIT 1
Excerpt from error log:
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] mod_python (pid=8262, interpreter='127.0.1.1', phase='PythonHandler', handler='django.core.handlers.modpython'): Application error
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] ServerName: '127.0.1.1'
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] DocumentRoot: '/var/www'
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] URI: '/test'
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] Location: '/test'
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] Directory: None
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] Filename: '/www/test/wsgi.py'
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] PathInfo: ''
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/modpython.py", line 180, in handler\n return ModPythonHandler()(req)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/modpython.py", line 158, in __call__\n response = self.get_response(request)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, in get_response\n response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception\n return callback(request, **param_dict)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view\n response = view_func(request, *args, **kwargs)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error\n t = loader.get_template(template_name) # You need to create a 500.html template.
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template\n template, origin = find_template(template_name)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template\n raise TemplateDoesNotExist(name)
[Tue Mar 05 22:28:22 2013] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html
I would try restarting apache. I've noticed inconsistencies in how urls are handled after any change. This sounds very similar to a problem I had when a url would sometimes load on refresh.
I have a Django 1.4 application on a Centos 6.2 server (running apache, mysql, php) using mod_wsgi with my project deployed in a virtual env. The application itself is one I've been using for several years on a hosted service and I am now deploying on my own rackspace cloud server. The exact version of the app is running fine elsewhere, so this issue is about how I have deployed it. It's my first python/django deployment - I have set up dozens of LAMP sites previously, so it's my lack of familiarity with Django deployments that is clearly holding me back.
The app works fine on my server with DEBUG = TRUE in the project's settings.py file, but when I change this to FALSE the front-end of the site produces [500] Internal Server Errors.
I am aware that with DEBUG set to OFF, apache is now serving my static files via mod_wsgi (mod_wsgi is working fine), which leads me to believe 'something' in my configuration is preventing this. I have run the ./manage.py collectstatic command which populated the /static directory in the /myproject folder.
I have been working on this for weeks now, reading as many deployment guides as I can find, but so far no joy. Your assistance would be very much appreciated.
Here are the relevant declarations in my project's settings.py file:
############ settings.py #############
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = '/opt/virtual/myproject/static/localtv/media/'
MEDIA_URL = 'http://example.org/static/localtv/media/'
STATIC_ROOT = '/opt/virtual/myproject/static/'
STATIC_URL = 'http://example.org/static/'
And here is the wsgi.py file:
############# wsgi.py #################
import os
import sys
import site
site.addsitedir('/opt/virtual/myapp/lib/python2.7/site-packages')
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
sys.path.append('/opt/virtual')
sys.path.append('/opt/virtual/myproject')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
My virtual host declaration in httpd.conf looks like this:
############ virtual host declaration in httpd.conf ##############
<VirtualHost *:80>
ServerName example.org
ServerAlias www.example.org
DocumentRoot /opt/virtual/myproject
Alias /robots.txt /opt/virtual/myproject/static/robots.txt
Alias /favicon.ico /opt/virtual/myproject/static/favicon.ico
AliasMatch ^/([^/]*\.css) /opt/virtual/myproject/static/styles/$1
Alias /static/ /opt/virtual/myproject/static/
Alias /media/ /opt/virtual/myproject/static/media
Alias /images /opt/virtual/myproject/static/images
<Directory /opt/virtual/myproject/static>
Order deny,allow
Allow from all
</Directory>
<Directory /opt/virtual/myproject/static/media>
Order deny,allow
Allow from all
</Directory>
WSGIDaemonProcess example.org python-path=/opt/virtual/myapp/lib/python2.7/site-packages
WSGIProcessGroup example.org
WSGIScriptAlias / /opt/virtual/myproject/application/wsgi.py
<Directory /opt/virtual/myproject>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
My .bashrc file in /ROOT looks like this:
########### .bashrc ##################
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
alias python='/opt/bin/python2.7'
export PYTHONPATH=/opt/virtual/myapp/lib/python2.7/site-packages:$PYTHONPATH
And finally, my error_log showing the Traceback:
############### error_log ###############
[Mon Jul 09 09:21:13 2012] [error] <WSGIRequest
[Mon Jul 09 09:21:13 2012] [error] path:/,
[Mon Jul 09 09:21:13 2012] [error] GET:<QueryDict: {}>,
[Mon Jul 09 09:21:13 2012] [error] POST:<QueryDict: {}>,
[Mon Jul 09 09:21:13 2012] [error] 'DOCUMENT_ROOT': '/opt/virtual/myproject',
[Mon Jul 09 09:21:13 2012] [error] 'GATEWAY_INTERFACE': 'CGI/1.1',
[Mon Jul 09 09:21:13 2012] [error] 'HTTP_ACCEPT': "*/*",
[Mon Jul 09 09:21:13 2012] [error] 'HTTP_HOST': 'example.org',
[Mon Jul 09 09:21:13 2012] [error] 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
[Mon Jul 09 09:21:13 2012] [error] 'PATH_INFO': u'/',
[Mon Jul 09 09:21:13 2012] [error] 'PATH_TRANSLATED': '/opt/virtual/myproject/application/wsgi.py/',
[Mon Jul 09 09:21:13 2012] [error] 'QUERY_STRING': '',
[Mon Jul 09 09:21:13 2012] [error] 'REMOTE_ADDR': '99.99.99.99',
[Mon Jul 09 09:21:13 2012] [error] 'REMOTE_PORT': '99999',
[Mon Jul 09 09:21:13 2012] [error] 'REQUEST_METHOD': 'GET',
[Mon Jul 09 09:21:13 2012] [error] 'REQUEST_URI': '/',
[Mon Jul 09 09:21:13 2012] [error] 'SCRIPT_FILENAME': '/opt/virtual/myproject/application/wsgi.py',
[Mon Jul 09 09:21:13 2012] [error] 'SCRIPT_NAME': u'',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_ADDR': '111.111.111.111',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_ADMIN': 'root#localhost',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_NAME': 'example.org',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_PORT': '80',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_PROTOCOL': 'HTTP/1.0',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_SIGNATURE': '<address>Apache/2.2.15 (CentOS) Server at example.org Port 80</address>\\n',
[Mon Jul 09 09:21:13 2012] [error] 'SERVER_SOFTWARE': 'Apache/2.2.15 (CentOS)',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.application_group': 'example.org|',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.callable_object': 'application',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.handler_script': '',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.input_chunked': '0',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.listener_host': '',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.listener_port': '80',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.process_group': 'example.org',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.request_handler': 'wsgi-script',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.script_reloading': '1',
[Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.version': (3, 3),
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.errors': <mod_wsgi.Log object at 0x7f34321aa530>,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f34320e4e40>,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.input': <mod_wsgi.Input object at 0x7f34320e02b0>,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.multiprocess': False,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.multithread': True,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.run_once': False,
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.url_scheme': 'http',
[Mon Jul 09 09:21:13 2012] [error] 'wsgi.version': (1, 1)}>
[Mon Jul 09 09:21:13 2012] [error] -------------------------------------------------------------------------------
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] mod_wsgi (pid=21520): Exception occurred processing WSGI script '/opt/virtual/myproject/application/wsgi.py'.
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] Traceback (most recent call last):
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = self.get_response(request)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return callback(request, **param_dict)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = view_func(request, *args, **kwargs)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/views/defaults.py", line 33, in server_error
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return http.HttpResponseServerError(t.render(Context({})))
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 140, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self._render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return compiled_parent._render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] result = block.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = view_func(request, *args, **kwargs)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/views/defaults.py", line 33, in server_error
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return http.HttpResponseServerError(t.render(Context({})))
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 140, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self._render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return compiled_parent._render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] result = block.nodelist.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/templatetags/compress.py", line 91, in render
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] rendered_output = compressor.output(self.mode, forced=forced)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/css.py", line 53, in output
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] ret.append(subnode.output(*args, **kwargs))
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/css.py", line 55, in output
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return super(CssCompressor, self).output(*args, **kwargs)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 221, in output
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] finished_content = self.handle_output(mode, filtered_content, forced)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 233, in handle_output
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return output_func(mode, content, forced)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 245, in output_file
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] self.storage.save(new_filepath, ContentFile(content))
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/files/storage.py", line 45, in save
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] name = self._save(name, content)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/files/storage.py", line 168, in _save
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] os.makedirs(directory)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/os.py", line 157, in makedirs
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] mkdir(name, mode)
[Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] OSError: [Errno 13] Permission denied: '/opt/virtual/myproject/static/CACHE/css'
I have been receiving the same error as you under almost similar conditions (I was running Ubuntu, not CentOS).
As you noticed, when running with DEBUG = FALSE, you are in fact running through wsgi. This means that when running with DEBUG = TRUE, you are actually using your user's privileges, while when running with DEBUG = FALSE, you are running using Apache's user's privileges. The user that Apache uses is www-data.
www-data is neither the owner nor in the group of users that own /var/www. This means that www-data is treated as other and has the permissions set to others.
The BAD solution to this would be to do:
sudo chmod -R 777 /var/www/
This would give everyone full access to everything in /var/www/, which is obviously a very bad idea.
Another BAD solution would be to do:
sudo chown -R www-data /var/www/
This would change the owner to www-data, which opens security vulnerabilities.
The GOOD solution would be:
sudo groupadd varwwwusers
sudo adduser www-data varwwwusers
sudo chgrp -R varwwwusers /var/www/
sudo chmod -R 770 /var/www/
This adds www-data to the varwwwusers group, which is then set as the group for /var/www/ and all of its subfolders. chmod will give read, write, execute permissions to the owner and the group, while blocking any other users from accessing it.
Dear Python/Django expert,
Due to recent server migration, my python-powered django app throws a 500 page. The log file is listed below. Can you please give me some help in diagnosing this problem?
==========================
[haiyang#web aihaiyang]$ tail ~/logs/user/error_django_aihaiyang_log
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] return callback(request, **param_dict), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/utils/decorators.py", line 93, in _wrapped_view, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] response = view_func(request, *args, **kwargs), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/views/defaults.py", line 30, in server_error, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] t = loader.get_template(template_name) # You need to create a 500.html template., referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/template/loader.py", line 157, in get_template, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] template, origin = find_template(template_name), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/template/loader.py", line 138, in find_template, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] raise TemplateDoesNotExist(name), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html, referer: http://aihaiyang.com/synlex/syntactic/
=========================
Thanks,
Haiyang
You need to create a 500.html template and put it in your template_dir
Template does not exist: 500.html