Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_wsgi for correct version of python3

I am setting up a Django server on Ubuntu 12.04 LTS, and I am having trouble installing mod-wsgi with the correct version of python. I have built my site locally with python 3.3, and Ubuntu 12.04 comes bundled with python 3.2. I suppose I could, but would rather not just use 3.2 instead of 3.3, so I installed python 3.3 alongside 3.2. I have everything installed for python 3.3 except for mod-wsgi.

On my local machine that is running python3.3 installing libapache2-mod-wsgi-py3 with sudo apt-get install libapache2-mod-wsgi-py3 installs it for python3.3. However on the Ubuntu server, running that same code installs it for python3.2 such that the web server runs 3.2 and can't find django.

Is there a way to disable python3.2, or point the script to install it for python 3.3?

EDIT: after looking into it more, python3.2 was not bundled with ubuntu, instead it was installed with libapache2-mod-wsgi-py3

like image 512
Hat Avatar asked Jan 03 '14 21:01

Hat


People also ask

Where is Mod_wsgi so?

If installing the Apache module by hand, the file is called 'mod_wsgi.so'. The compiled Apache module can be found in the “. libs” subdirectory. The name of the file should be kept the same when copied into its appropriate location.

How do I check my Wsgi mod version?

mod_wsgi – Get The Versiond/example.com. conf if you use CentOS, RHEL etc., or to /etc/apache2/conf. d/example.com. conf for Debian, Ubuntu etc.

What is WSGIPythonHome?

WSGIPythonHome prefix|prefix:exec_prefix. Context: server config. Used to indicate to Python when it is initialised where its library files are installed.


2 Answers

I found out how to build mod_wsgi, to be used with Python 3.3.5, on Ubuntu 12.04 LTS.

The trick is to be able to install the python3.3-dev package, which isn't supported on Ubuntu 12.04 LTS ("precise"). There is a 3rd party repository maintained by Felix Krull that makes old and new Python builds available (Kudos to Felix!):

https://launchpad.net/~fkrull/+archive/deadsnakes

To install Felix's repository:

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update

Before starting to build mod_wsgi we need the apache2-dev package ...

sudo apt-get install apache2-dev

... and get the python3.3-dev package (this actually installs python3.3 as well!)

sudo apt-get install python3.3-dev

Download the mod_wsgi code and build it by providing the path to the freshly installed Python libs and headers (/usr/bin/python3.3). The download link with the latest mod_wsgi release can be found at:

https://github.com/GrahamDumpleton/mod_wsgi/releases

cd /usr/local/src
sudo wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/modwsgi/mod_wsgi-3.4.tar.gz
sudo tar -zxvf mod_wsgi-3.4.tar.gz 
cd mod_wsgi-3.4/
sudo ./configure --with-python=/usr/bin/python3.3
sudo make
sudo make install

mod_wsgi.so is placed in /usr/lib/apache2/modules/

Optional step: Since they were missing, I manually (re)created the wsgi.conf and wsgi.load files in /etc/apache2/mods-available (although I didn't have to set any specific option).

wsgi.conf:

<IfModule mod_wsgi.c>

    # See http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives

    #WSGISocketPrefix: Configure directory to use for daemon sockets.

    #WSGISocketPrefix /var/run/apache2/wsgi

    #WSGIPythonOptimize: Enables basic Python optimisation features.

    #WSGIPythonOptimize 0

    #WSGIPythonPath: Additional directories to search for Python modules,
    #                overriding the PYTHONPATH environment variable.

    #WSGIPythonPath directory|directory-1:directory-2:...


    #WSGIPythonEggs: Directory to use for Python eggs cache.

    #WSGIPythonEggs directory

    #WSGIRestrictEmbedded: Enable restrictions on use of embedded mode. 

    #WSGIRestrictEmbedded On|Off

    #WSGIRestrictStdin: Enable restrictions on use of STDIN.
    #WSGIRestrictStdout: Enable restrictions on use of STDOUT.
    #WSGIRestrictSignal: Enable restrictions on use of signal().

    #WSGIRestrictStdin On
    #WSGIRestrictStdout On
    #WSGIRestrictSignal On

    #WSGIAcceptMutex: Specify type of accept mutex used by daemon processes.

    #WSGIAcceptMutex default

    #WSGIImportScript: Specify a script file to be loaded on process start. 

    #WSGIImportScript process-group=name application-group=name

    #WSGILazyInitialization: Enable/disable lazy initialisation of Python. 

    #WSGILazyInitialization On|Off

</IfModule>

wsgi.load:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

Finally, mod_wsgi can be enabled by creating symbolic links like this:

cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/wsgi.conf wsgi.conf
sudo ln -s ../mods-available/wsgi.load wsgi.load

Let me know if this also worked out for you!

like image 164
Visionscaper Avatar answered Sep 17 '22 17:09

Visionscaper


I did it in Centos 6.7, just create the file wsgi.conf in : /etc/httpd/conf.d , specify the file path mod_wsgi.so: LoadModule wsgi_module /etc/httpd/modules/mod_wsgi.so After downloading and unzipping the file mod_wsgi_x.x.tar, you need to do something extra after specifying the version of python:

./configure  --with-python=/usr/local/bin/python3.4
LD_RUN_PATH=/usr/local/lib make
make install

This will embed the non standard directory location into the mod_wsgi.so, as explained Graham Dumpleton in the following link : GoogleGroups answers

like image 28
Brayan Loayza Avatar answered Sep 19 '22 17:09

Brayan Loayza