Using multiple versions with Passenger

Overview

Passenger provides an intelligent polyglot launcher interface for managing Node.js, Ruby, and Python processes. This can be teamed up with pyenv to effortlessly launch multiple Python applications with a single shell command and .htaccess directive.

These steps are only necessary to use supplementary Python versions available on the server. If the default version works satisfactorily, then no further changes are necessary.

Usage

Applying what has been learned from KB article: “Changing python versions“, create a directory structure compatible with Passenger:

cd /var/www
mkdir -p mypyapp/{public,tmp}
cd mypyapp

Now assign it a Python interpreter. We’ll use 3.3.5:

pyenv local 3.3.5

Lastly, inform Passenger to use the pyenv-compatible python shim by adding PassengerPython /.socket/python/shims/python to a .htaccess file in public/

echo "PassengerPython /.socket/python/shims/python" > /var/www/mypyapp/public/.htaccess

Important: using pyenv’s shim system is considerably slower than accessing python directly, because a series of shell subprocesses are launched to resolve the python process necessary to satisfy a request. If using pyenv with Passenger, consider adapting it to the FastCGI specification for background persistence.

See also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.