Django Application deployment on linux server - python

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.

Related

500 Internal Server Error with Django 1.6 on EC2, django.wsgi

I've just finished installing (or attempting to install) Django 1.6 on an EC2 server, but I seem to be having trouble with django.wsgi.
I've installed Django 1.6, httpd, and mod_wsgi, and I'm getting the "The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root#localhost..."
I get that I've made a misstep somewhere, but I can't seem to make out what the error logs are trying to tell me. I see there are some database errors near the bottom, and I haven't gotten to setting any up yet, but surely the errors above are from a different issue?
Here's is the latest from the error log:
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1973): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] self.load_middleware()
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] module = import_module(module_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] __import__(name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] class Permission(models.Model):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1976): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] self.load_middleware()
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] module = import_module(module_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] __import__(name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] class Permission(models.Model):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base
My django.wsgi is as follows:
import os,sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/home/ec2-user/Django-1.6/joshsite/joshsite')
sys.path.append('/home/ec2-user/Django-1.6/joshsite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'joshsite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And I've added this in to the httpd.conf
<VirtualHost *:80>
DocumentRoot /home/ec2-user/Django-1.6/joshsite
ServerName ec2-54-187-46-240.us-west-2.compute.amazonaws.com
ErrorLog /home/ec2-user/Django-1.6/joshsite/logs/apache_error.log
CustomLog /home/ec2-user/Django-1.6/joshsite/logs/apache_access.log combined
WSGIScriptAlias / /home/ec2-user/Django-1.6/apache/django.wsgi
<Directory /home/ec2-user/Django-1.6/joshsite/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ec2-user/Django-1.6/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
Alias /media/ /ec2-user/Django-1.6/joshsite/media/
</VirtualHost>
Here are the contents of settings.py:
"""
Django settings for joshsite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ***
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'joshsite.urls'
WSGI_APPLICATION = 'joshsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': '**',
'PASSWORD': '**',
'HOST': '',
'PORT': '',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
Here is my urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'joshsite.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', 'joshsite.views.home', name='home'),
)
Update:
Sometimes at /, I get a 404 error:
Request Method: GET
Request URL: http://ec2-54-187-46-240.us-west-2.compute.amazonaws.com/
Using the URLconf defined in joshsite.urls, Django tried these URL patterns, in this order:
^admin/
^home/ [name='home']
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Thank you in advance for any assistance.
But then after refreshing it sometimes goes back to a 500, almost as if chosen at random.
Check your DATABASE settings in settings.py. Looks like your ENGINE is bad. Try changing to:
'ENGINE': 'django.db.backends.mysql',
If this doesn't work, please post your database settings.

apache2 and mod wsgi : Target WSGI script cannot be loaded as Python module

I am trying to install mod_wsgi on apache2, on ubuntu.
So I install libapache2-mod-wsgi package, I activate him with a2enmod.
I got a web site (languageAnalyz), that I am trying to use with mod_wsgi.
When I call localhost/languageAnalyz, I got an error 500.
In apache2 log, I can see this :
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): Target WSGI script '/var/www/languageAnalyz/test-wsgi.py' cannot be loaded as Python module.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/test-wsgi.py' ignored.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/test-wsgi.py", line 10, in <module>
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] WSGIServer(app).run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] sock = self._setupSocket()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] req.run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] self._end(appStatus, protocolStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] sys.exit(appStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] SystemExit: 0
I googled this error, and I find lot of solutions (most of the times for Django project).
What I undsertand, is that I need to create a __init__.py file.
What I did, here is my __init__.py file :
__all__ = ['app','get_size_dir','get_nbrf_dir','getStats'] #name of my functions
import index # my three python files
import analyz
import test-wsgi
In the __all__ list, this is the name of the functions in the three files.
I am just trying to launch test-wsgi.py, and get the same error 500.
Here is my test-wsgi.py file :
import os,sys
sys.path.append(os.path.dirname(__file__))
from cgi import escape,parse_qs
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
start_response('200 OK',[('Content-Type','text/plain; charset=utf-8')])
yield "hello world!"
WSGIServer(app).run()
So what's wrong ?
Thank you,
Edit :
here is my apache2 conf :
WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
...
<Directory /var/www/languageAnalyz/>
Options +Indexes ExecCGI FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.py
SetHandler wsgi-script
</Directory>
...
</VirtualHost>
Edit_bis :
So I try to do as I read on django doc.
I change my apache2 conf to :
WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
...
WSGIScriptAlias /IPA /var/www/languageAnalyz/testwsgi.py
<Directory /var/www/languageAnalyz/>
Options +Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex testwsgi.py
</Directory>
...
</VirtualHost>
I restart apache2, and I got the same error, and one more before :
[Sun Aug 25 12:47:18 2013] [notice] caught SIGTERM, shutting down
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: wrapper mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: process manager initialized (pid 7879)
[Sun Aug 25 12:47:19 2013] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Sun Aug 25 12:47:19 2013] [notice] mod_python: using mutex_directory /tmp
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Compiled for Python/2.7.3.
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Runtime using Python/2.7.4.
[Sun Aug 25 12:47:19 2013] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 PHP/5.4.9-4ubuntu2.2 mod_python/3.3.1 Python/2.7.4 mod_ruby/1.2.6 Ruby/1.8.7(2012-02-08) mod_wsgi/3.4 configured$
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] Status: 200 OK\r
[Sun Aug 25 12:47:19 2013] [error] Content-Type: text/plain; charset=utf-8\r
[Sun Aug 25 12:47:19 2013] [error] \r
[Sun Aug 25 12:47:19 2013] [error] hello world!
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): Target WSGI script '/var/www/languageAnalyz/testwsgi.py' cannot be loaded as Python module.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/testwsgi.py' ignored.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/testwsgi.py", line 10, in <module>
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] WSGIServer(app).run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] sock = self._setupSocket()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] req.run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] self._end(appStatus, protocolStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] sys.exit(appStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] SystemExit: 0
Edit_ter :
Ok, I just successfully launch testwsgi.py. I change my app function into application, and I add some lines at the end :
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('localhost', 8080, application)
server.serve_forever()
I event don't know, why it's working, why it was not working before. ... And now I got some problem to open files, with their path (config files, or templates files ...)
[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/analyz.py", line 22, in getStats
[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1] flangs=open('config/languages.yml')
I try with absolute path, it didn't work too ...
You would appear to be following the wrong documentation for starters. For mod_wsgi use:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
You appear to be using documentation for FASTCGI deployment.
Also, you cannot do:
import test-wsgi
A Python module name cannot have '-' in it.
In summary, go reread (or read) the Django documentation on deployment.
For me the problem was wsgi python version mismatch. I was using python 3, so:
$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
I had the same problem for a differnt file and making the file world executable fixed it for me. You would of course want to lock it down to the required user after you have narrowed this down as your issue:
chmod a+x test-wsgi.py

Exception occurred processing WSGI script - WAMP Server

Installed Python and Django on a Windows Server 2008 R2 Wamp Machine. Everything's fine, except a ported version of a django/python website which were on a LAMP machine previously.
500 internal server error when accessing the vhost via web browser
I get this error log from apache:
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] mod_wsgi (pid=1788): Exception occurred processing WSGI script 'C:/Wamp/www/mysite_com/mysite_com.wsgi'.
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 255, in __call__
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] response = self.get_response(request)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 178, in get_response
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 220, in handle_uncaught_exception
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] if resolver.urlconf_module is None:
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\urlresolvers.py", line 342, in urlconf_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] self._urlconf_module = import_module(self.urlconf_name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] __import__(name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] ImportError: No module named urls
This is my .wsgi app:
import os, sys
sys.path.append('c:/Wamp/www/')
os.environ ['DJANGO_SETTINGS_MODULE'] = 'mysite_com.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And my apache vhosts
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot "C:/Wamp/www/mysite_com/"
WSGIScriptAlias / "C:/Wamp/www/mysite_com/mysite_com.wsgi"
</VirtualHost>
folder structure
\www
\mysite_com
\__init__.py
\settings.py
\urls.py
\manage.py
\mysite_com.wsgi
Any advice?
Thanks
You're adding the site path to your system path wrong. See in Linux you would use forward slashes '/' while in windows (which you seem to be using) backward slashes '\'. Of course, you need to double them up so it won't be rendered as escape strings:
sys.path.append('C:\\wamp\\www')
of course, it would be much easier like this:
sys.path.append(r'C:\wamp\www')
And see - your server can find the wsgi application because you told apache where to find it, so it complains about the next module that it can't find (which just happens to be urls.py). I already answered in a comment but I thought an explanation of why you saw the error that specific way would help.
p.s.
If that still doesn't work you might need to append the path to your actual application:
sys.path.append(r'C:\Wamp\www\mysite_com')

Internal Server Error Apache and WSGI (With Flask)

(sorry fist question and not yet answered anything, I'll get to it!)
I am trying to setup Flask with Apache2 and mod_wsgi in an ubuntu 12.04 virtual machine, mainly so that I know how to do it in the future when I come to deploying a Flask application. Just so that you guys know, I am new to Python and Flask, but I am familiar with PHP, and as a consequence general programming practices.
I am following this tutorial to setup Flask. I have successfully setup the test application defined in the tutorial, however when I try to setup an existing application using the tutorial I get the following error:
Internal Server Error
The server encountered an internal error and was unable to complete your request.
Either the server is overloaded or there is an error in the application.
Here is my app.py file, I suspect there is an error here but I can't find it, I added in the app run code from the tutorial In hopes it would work but it didn't, I got the same error and I could never get an error log, so I switched back to "app.run()" and when I restart apache I get an error log:
import flask
import settings
# Views
from main import Main
from login import Login
from remote import Remote
from music import Music
app = flask.Flask(__name__)
app.secret_key = settings.secret_key
# Routes
app.add_url_rule('/',
view_func=Main.as_view('main'),
methods=["GET"])
app.add_url_rule('/<page>/',
view_func=Main.as_view('page'),
methods=["GET"])
app.add_url_rule('/login/',
view_func=Login.as_view('login'),
methods=["GET", "POST"])
app.add_url_rule('/remote/',
view_func=Remote.as_view('remote'),
methods=['GET', 'POST'])
app.add_url_rule('/music/',
view_func=Music.as_view('music'),
methods=['GET'])
#app.errorhandler(404)
def page_not_found(error):
return flask.render_template('404.html'), 404
#app.debug = True
app.run()
#if __name__ == '__main__':
#"Are we in the __main__ scope? Start test server."
#app.run(host='0.0.0.0',port=5000,debug=True)
And here is the error.log file that is returned. I have read it b
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5739): Target WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi' cannot be loaded as Python module.
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5739): Exception occurred processing WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi'.
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/wsgi/learningflask.wsgi", line 3, in <module>
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] from app import app as application
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/apps/learningflask/app.py", line 35, in <module>
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] app.run()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] run_simple(host, port, self, **options)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 710, in run_simple
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] inner()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 692, in inner
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] passthrough_errors, ssl_context).serve_forever()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 436, in serve_forever
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] HTTPServer.serve_forever(self)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] r, w, e = select.select([self], [], [], poll_interval)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] error: (4, 'Interrupted system call')
If you need any more information then I would be happy to provide it, I would appreciate all the help I can get.
EDIT:
Here is my learningflask.wsgi file:
import sys
sys.path.insert(0, '/home/carwyn/public_html/apps/learningflask')
from app import app as application
And here is my available-sites apache file-thing (called learningflask), it pretty much just follows the tutorial one but is set up for the tutorial application:
<VirtualHost *:8081>
# ---- Configure VirtualHost Defaults ----
ServerAdmin carwynjohnnelson#aol.com
DocumentRoot /home/carwyn/public_html/http/learningflask/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/carwyn/public_html/http/learningflask/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# ---- Configure WSGI Listener(s) ----
WSGIDaemonProcess learningflask user=www-data group=www-data threads=5
WSGIScriptAlias /learningflask /home/carwyn/public_html/wsgi/learningflask.wsgi
<Directory /home/carwyn/public_html/http/learningflask>
WSGIProcessGroup learningflask
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# ---- Configure Logging ----
ErrorLog /home/carwyn/public_html/logs/error.log
LogLevel warn
CustomLog /home/carwyn/public_html/logs/access.log combined
</VirtualHost>
SECOND EDIT:
I hope this might help, I removed the app.run and reloaded the page and I get the error. Then I looked in my previously cleared error log and get nothing. So i restarted apache and looked in my error log and I get this:
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5908): Target WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi' cannot be loaded as Python module.
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5908): Exception occurred processing WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi'.
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/wsgi/learningflask.wsgi", line 3, in <module>
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] from app import app as application
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/apps/learningflask/app.py", line 35, in <module>
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] #app.run()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] run_simple(host, port, self, **options)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 710, in run_simple
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] inner()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 692, in inner
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] passthrough_errors, ssl_context).serve_forever()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 436, in serve_forever
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] HTTPServer.serve_forever(self)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] r, w, e = select.select([self], [], [], poll_interval)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] error: (4, 'Interrupted system call')
You should not be calling:
app.run()
This is starting Flask's own HTTP server within the Apache process.
There was a reason it was inside of an if() statement checking to see whether __name__ was '__main__'. That was to ensure it was only called when the script was run from command line Python interpreter. You do not want it to be run under Apache.

webpy with mod_wsgi on apache2 - weird pymongo bson error

I'm running webpy with apache2. This is a really weird error that has got me flummoxed. Have never seen such an error before and I'm wondering what might be the cause.
The error is in the bson pymongo module.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] mod_wsgi (pid=27117): Target WSGI script '/var/www/webpy-app/borg/src/app.py' cannot be loaded
as Python module.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] mod_wsgi (pid=27117): Exception occurred processing WSGI script '/var/www/webpy-app/borg/src/ap
p.py'.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] Traceback (most recent call last):
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/var/www/webpy-app/borg/src/app.py", line 1, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] import web,json,csv,pymongo,pdb,sys
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/__init__.py", line 61, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/connection.py", line 39, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/mongo_client.py", line 44, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/__
init__.py", line 41, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/_c
bson.py", line 7, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/_c
bson.py", line 6, in __bootstrap__
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] AttributeError: PyCapsule_Import "datetime.datetime_CAPI" is not valid
Here's the WSGI config in httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /borg /var/www/webpy-app/borg/src/app.py/
WSGIPythonPath /opt/python2.7/lib/python2.7/site-packages/
Alias /borg/static /var/www/webpy-app/borg/src/static/
AddType text/html .py
<Directory /var/www/webpy-app/>
Order deny,allow
Allow from all
</Directory>
Is the error because of a python library incompatibility issue ? Am not sure. Any help will be greatly appreciated.
Figured this out by setting WSGIPythonHome to the appropriate location. WSGI was looking at an old Python library.

Categories