Faizan Ali
Faizan Ali

Reputation: 1013

Django app not being served with Python3.5 and httpd

I have a Django app hosted on:

Server version: Apache/2.4.6 (CentOS)
Server built:   Oct 19 2017 20:39:16

here's my django.conf file:

    Alias /static /home/faizan/myproject/static
    <Directory /home/faizan/myproject/static>
        Require all granted
    </Directory>

    <Directory /home/faizan/myproject/myproject>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    WSGIDaemonProcess myproject python-path=/home/faizan/myproject:/home/faizan/myproject/myprojectenv/lib/python3.5/site-packages
    WSGIProcessGroup myproject
    WSGIScriptAlias / /home/faizan/myproject/myproject/wsgi.py

My application was working when I had python 2.7 installed in my virtual environment and had django.conf like this:

Alias /static /home/faizan/myproject/static
<Directory /home/faizan/myproject/static>
    Require all granted
</Directory>

<Directory /home/faizan/myproject/myproject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess myproject python-path=/home/faizan/myproject:/home/faizan/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/faizan/myproject/myproject/wsgi.py

Upvotes: 0

Views: 201

Answers (1)

Ykh
Ykh

Reputation: 7717

Apache2 with mod_wsgi,the mod_wsgi binary has to be compiled against one Python version only and only one instance of a compiled mod_wsgi module can be loaded into Apache at a time.

You install mod_wsgi with python2.7,if now you system defalut python is python 3.5,you can reinstall mod_wsgi by(for ubuntu,i don't know how to reinstall for centos,but all you need to do is reinstall mod_wsgi with the python(must be same install) with you virtualenv use):

sudo apt-get install libapache2-mod-wsgi-py3

If you system defalut python is not python3.5,download mod_wsgi from here,and manual compilation and installation with python you used in virtualenv(also for ubuntu):

    tar xvfz mod_wsgi-X.Y.tar.gz
    cd mod_wsgi-X.Y/ 
    sudo ./configure --with-python=/usr/bin/python3.5 
    sudo make 
    sudo make install 

    sudo nano /etc/apache2/mods-available/wsgi.load 
    LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so # write this to wsgi.load

    sudo a2enmod wsgi
    sudo service apache2 restart

Upvotes: 1

Related Questions