On Ubuntu 14.04, using Apache2 with package libapache2-mod-wsgi-py3 installed gives errors in /var/log/apache2/error.log

The way to reproduce is straightforward :

sudo apt-get install apache2
sudo service apache2 restart
# /var/log/apache2/error.log is "clean"
sudo apt-get install libapache2-mod-wsgi-py3
sudo service apache2 restart

/var/log/apache2/error.log gives the following error :

[Mon Jan 05 16:51:53.641332 2015] [:error] [pid 3141:tid 140703516379008] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Mon Jan 05 16:51:53.643563 2015] [:error] [pid 3141:tid 140703516379008] Traceback (most recent call last):
[Mon Jan 05 16:51:53.643633 2015] [:error] [pid 3141:tid 140703516379008]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Mon Jan 05 16:51:53.644350 2015] [:error] [pid 3141:tid 140703516379008]     assert tlock is not None
[Mon Jan 05 16:51:53.643449 2015] [:error] [pid 3140:tid 140703516379008] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Mon Jan 05 16:51:53.644456 2015] [:error] [pid 3140:tid 140703516379008] Traceback (most recent call last):
[Mon Jan 05 16:51:53.644514 2015] [:error] [pid 3140:tid 140703516379008]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Mon Jan 05 16:51:53.645052 2015] [:error] [pid 3140:tid 140703516379008]     assert tlock is not None
[Mon Jan 05 16:51:53.645119 2015] [:error] [pid 3141:tid 140703516379008] AssertionError: 
[Mon Jan 05 16:51:53.647513 2015] [:error] [pid 3140:tid 140703516379008] AssertionError: 

How to get it work error-free?

share|improve this question
up vote 13 down vote accepted

Ubuntu 14.04 comes with mod_wsgi 3.4. According to https://code.djangoproject.com/ticket/22948#comment:2 we need to use mod_wsgi version 4.2+ for Python 3.4.

The best way to install mod_wsgi to the latest version is to get it with pip (can be in virtualenv) and then install its module to apache system-wide. In my case I use virtualenv set in /venv_path.

1) Remove problematic package and install dependency

sudo apt-get remove libapache2-mod-wsgi-py3
sudo apt-get install apache2-dev

2) Install mod_wsgi in virtualenv with pip

. /venv_path/bin/activate
pip install mod_wsgi

3) Install into Apache (system-wide)

sudo /venv_path/bin/mod_wsgi-express install-module
sudo vi /etc/apache2/mods-available/wsgi_express.load /etc/apache2/mods-available/wsgi_express.conf

Content of /etc/apache2/mods-available/wsgi_express.load

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py34.cpython-34m.so

Content of /etc/apache2/mods-available/wsgi_express.conf

WSGIPythonHome /venv_path

4) Enable the module and restart Apache.

sudo a2enmod wsgi_express
sudo service apache2 restart

5) Check that there are no errors in /var/log/apache2/error.log

share|improve this answer
1  
You may want to mention that the command to create a virtualenv is virtualenv -p python3.4 DIRECTORY, or for 3.4+, better: pyvenv-3.4 DIRECTORY. – nyuszika7h Jan 6 '15 at 15:40
1  
That's correct ... but I didn't mention it to keep the focus on the mod_wsgi question. – samb Jan 6 '15 at 16:01
1  
But since you're already using virtualenv in your example, why not also mention how to create it? – nyuszika7h Jan 6 '15 at 19:23
    
If someone else gets an error (cannot open shared object file: No such file or directory) when trying to do this, remember to switch the version in step 3. I was using Python 3.5, 64-bit. mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so. If you don't know which version you have, go to the folder (/usr/lib/apache2/modules/) and look. This answer seems to be based on 32-bit python 3.4. – Deleet Oct 15 '16 at 4:05
    
this method is python-version-agnostic and worked for me with python3.6 sudo /venv_path/bin/mod_wsgi-express install-module in step 3 will print the paths that you need to put in the wsgi_express files – gevra Oct 30 '17 at 21:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.