How to properly configure paths and permissions for python to deploy Django + mod_wsgi?

The problem I encountered is my wsgi file, which cannot import wsgi handlers correctly.

/var/log/apache2/error.log reports:

ImportError: no module named django.core.handlers.wsgi

A Google search results in a couple of results, mainly related to permission errors, because www-datait cannot read certain files and / or the pythonpath is incorrect. Some of the solutions are vague or just do not work in my circumstances.

Background information ..

My / usr / lib directory ..

/usr/lib/python2.4
/usr/lib/python2.5
/usr/lib/python2.6
/usr/lib/python-django

The default python version is 2.5.2. If I open the interpreter as a regular user, I can import django.core.handlers.wsgino problem.

www-data, python , django.core.handlers.wsgi .

bashrc PYTHONPATH , django...

export PYTHONPATH=/home/meder/django-sites/:$PYTHONPATH

, :

django-sites/
   test

test - , django-admin createproject.

:

<VirtualHost *:80>
    ServerName beta.blah.com
    WSGIScriptAlias / /home/meder/django-sites/test/apache/django.wsgi
    Alias /media /home/meder/django-sites/test/media/
</VirtualHost>

/home/meder/django-sites/test/apache/django.wsgi:

import os, sys

sys.path.append('/usr/local/django')
sys.path.append('/home/meder/django-sites')
sys.path.append('/home/meder/django-sites/test')
os.environ['DJANGO_SETTINGS_MODULE'] = 'test.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

, - Debian Lenny, django 1.1.1 backports. , .

# 1 - ldd /usr/lib/apache2/modules/mod_wsgi.so:

meder@site:/usr/lib/apache2/modules$ ldd mod_wsgi.so
    libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0xb7d99000)
    libpthread.so.0 => /lib/libpthread.so.0 (0xb7d81000)
    libdl.so.2 => /lib/libdl.so.2 (0xb7d7c000)
    libutil.so.1 => /lib/libutil.so.1 (0xb7d78000)
    libm.so.6 => /lib/libm.so.6 (0xb7d52000)
    libc.so.6 => /lib/libc.so.6 (0xb7c14000)
    /lib/ld-linux.so.2 (0xb7efd000)

python 2.5, 2.4.

+3
3

Debian, , django /usr/lib/pymodules/python2.5, /usr/lib/python2.5/site-packages.

sys.path.append('/usr/lib/pymodules/python2.5') 

wsgi, , , .

+2

, sys.path. Mod_WSGI Django, Daemonized, ,

# Note these 2 lines
WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
WSGIProcessGroup site-1

Alias /media/ /usr/local/django/mysite/media/

<Directory /usr/local/django/mysite/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi

<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all

- , . , www-data django, , Apache - , - /, , DaemonProcess Group .

.

[1] - Django Mod_WSGI doc - http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

+1

, mod_wsgi Python 2.5 Python 2.4 2.6. Run:

ldd mod_wsgi.so

mod_wsgi.so, , , .

, mod_wsgi , , .

0

Source: https://habr.com/ru/post/1731503/


All Articles