1

I use a bunch of Ubuntu 16.04 + Apache 2.4 + Django 1.10 + Python3.5 + wsgi + virtualenv.

The apache configuration ordered following

WSGIDaemonProcess myproject python-path/home/admin/web/domen.com/private/myprojectenv:/home/admin/web/domen.com/private/myprojectenv/lib/python3.5/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/admin/web/domen.com/private/myproject/wsgi.py

wsgi.py standard

import os

from django.core.wsgi import get_wsgi_application



os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application()

Reinstall everything. Fat, you see the error 500. log: from django.core.wsgi import get_wsgi_application ImportError: No module named 'django'

  • are you using virtual env in your application? – Alexander Tyapkov Jan 21 '17 at 09:37
  • yes, it is located at the address /home/admin/web/domen.com/private/myprojectenv it`s name myprojectenv –  Jan 21 '17 at 09:41
  • then you have to activate in inside your wsgi.py – Alexander Tyapkov Jan 21 '17 at 09:42
  • Have a look at some configs here http://stackoverflow.com/questions/37250573/django-1-9-apache-error-import-django-core-handlers-wsgi-importerror-no-module – Alexander Tyapkov Jan 21 '17 at 09:47
  • It did not help. Still 2.7.12 –  Jan 21 '17 at 10:01
  • edit your question and post what you have done. It will help to understand what is wrong – Alexander Tyapkov Jan 21 '17 at 10:05
  • Edited. Showed in the pictures what you need –  Jan 21 '17 at 10:33
  • Have you installed libapache2-mod-wsgi-py3 and loaded it into apache? – daragua Jan 21 '17 at 11:12
  • Yes installed libapache2-mod-wsgi-py3, but not surrounded by –  Jan 21 '17 at 11:24
  • According to [wsgi's virtualenv section](http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html#daemon-mode-multiple-applications) try `WSGIDaemonProcess myproject python-home=/home/admin/web/domen.com/private/myprojectenv/`. However, the images you post indicate that Apache is still using the wrong mod-wsgi. Try deleting (with `apt`) mod-wsgi and reinstalling it, then enabling it using `a2enmod`? – daragua Jan 21 '17 at 12:00
  • Reinstall everything. Fat, you see the error 500. –  Jan 21 '17 at 12:13
  • OK, did you update the `WSGIDaemonProcess ...` line as in my previous comment? The `python-home=...` argument needs to point to your virtualenv's root directory (with `bin`, `lib`).. – daragua Jan 21 '17 at 13:25
  • Да, обновление. но до сих пор ошибка 500 `WSGIDaemonProcess myproject python-path=/home/admin/web/dome.com/private/:/home/admin/web/domen.com/private/myprojectenv/lib/python3.5/site-packages` –  Jan 21 '17 at 13:32

3 Answers3

0

I had the same problem and solved it installing the propper version of mod_wsgi to use with specific python version (I have 3.4). Check info here in the modwsgi readthedocs

paralosreg
  • 141
  • 1
  • 15
0

If you want to use the compiled version, you'll need to compile mod_wsgi against the Python version you want to run on. Point to the version of Python you want to use with the --with-python parameter. Here's an example.

wget "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.x.y.tar.gz"
tar -xzf '4.x.y.tar.gz'
cd ./mod_wsgi-4.x.y
./configure --with-python=/usr/local/bin/python3.5
make
make install

Good luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
0

I managed razobratsya a problem below will describe its solution.

My system Ununtu 16.04, Vesta panel 0.9.8-17 (including all blew nginx + apache).

Since I needed python3 for him, and I will describe, if you have nothing to pothon2 all except Similar Containers installed packages.

Install the package, and the environment itself Jango took from here https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-16-04

What has changed: wsgi.py

import os, sys

sys.path.append ( '/ home / admin / web / domen.com / private') # The path to the folder with Django project
from django.core.wsgi import get_wsgi_application

os.environ.setdefault ( "DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application ()

Apache Configuration for West Side:

<VirtualHost 172.11.11.11:8080>

    ServerName domen.com
    ServerAlias ​​www.domen.com
    ServerAdmin info@domen.com
    DocumentRoot /home/admin/web/domen.com/public_html
    ScriptAlias ​​/ cgi-bin / /home/admin/web/domen.com/cgi-bin/
    Alias ​​/ vstats / /home/admin/web/domen.com/stats/
    Alias ​​/ error / /home/admin/web/domen.com/document_errors/
    #SuexecUserGroup Admin admin
    CustomLog /var/log/apache2/domains/domen.com.bytes bytes
    CustomLog /var/log/apache2/domains/domen.com.log combined
    ErrorLog /var/log/apache2/domains/domen.com.error.log
    <Directory /home/admin/web/domen.com/public_html>
        AllowOverride All
        Options + Includes -Indexes + ExecCGI
        php_admin_value open_basedir /home/admin/web/domen.com/public_html:/home/admin/tmp
        php_admin_value upload_tmp_dir / home / admin / tmp
        php_admin_value session.save_path / home / admin / tmp
    </ Directory>
    <Directory /home/admin/web/domen.com/stats>
        AllowOverride All
    </ Directory>
  
<IfModule mod_ruid2.c>
        RMode config
        RGroups www-data
    </ IfModule>
    <IfModule itk.c>
        AssignUserID admin admin
    </ IfModule>

  Alias ​​/ static /home/admin/web/domen.com/private/static
<Directory /home/admin/web/domen.com/private/static>
        Require all granted
   </ Directory>


    <Directory /home/admin/web/domen.com/private/myproject>
        <Files wsgi.py>
           Require all granted
       </ Files>
      </ Directory>
     
    WSGIScriptAlias ​​/ /home/admin/web/domen.com/private/myproject/wsgi.py
    WSGIDaemonProcess myproject user = admin group = admin python-path = / home / admin / web / domen.com / private / env / lib / python3.5 / site-packages
    WSGIProcessGroup myproject
    
    IncludeOptional /home/admin/conf/web/apache2domen.com.conf*

</ VirtualHost>

I am satisfied by all of the admin. In WSGIDaemonProcess necessarily need to specify Ucero and Korhogo GROUP from all handled differently is a problem with access to the database

Initially block <IfModule mod_ruid2.c> looks like this:

 

<IfModule mod_ruid2.c>
        RMode config
        RUidGid admin admin
        RGroups www-data
    </ IfModule>

But I removed vnem RUidGid admin group admin, as it blocked the start and gave a 503 error (if anyone knows of such a feature then write in the comments)

This server is ready to run.