File uploads in a Passenger-backed application fail

Overview A file upload initiated in an application written in Ruby, Node, or Python launched through Passenger will fail to upload. Thus far, the confirmed failure occurs in RefineryCMS with a generic undefined route message following upload. Cause It is a conflict between upload screening and Passenger, but the underlying cause is not clearly understood. Upload…

Pyramid Quickstart

Overview Pyramid is a Python framework that is the spiritual successor to Pylon and Zope, frameworks popular in the mid-to-late 2000s. Pyramid is supported with on v6+ platforms using any Python version from 2.7 onward with Passenger. Quickstart All commands are done from the terminal for convenience. PREREQUISITE: create a suitable Passenger-compatible filesystem layout cd /var/www…

Flask Quickstart

Overview Flask is a Python microframework for building web sites with minimal overhead. Think of it as a lightweight version of Django with fewer features, but better speed. Flask is supported on v6+ platforms using Passenger. Quickstart All steps are done from the terminal. While it may be possible to deploy a Flask application without using terminal,…

pip install fails with “Permission denied” on Python 3+

Overview Python’s integrated package manager, pip, fails to install packages when Python 3.0 and above is used raising a PermissionError. Below is an abbreviated sample output: [myadmin@sol]$ pip install django Downloading/unpacking django Installing collected packages: django Cleaning up… Exception: Traceback (most recent call last): File “/.socket/python/python3.4/site-packages/pip/wheel.py”, line 205, in clobber os.makedirs(destdir) File “/.socket/python/python3.4/os.py”, line 237,…

Passenger application layout

Overview All Passenger applications require a compatible filesystem layout to launch and manage a Passenger-backed application. A layout consists of 4 features: Startup file Passenger loads this file to start the application Startup file names differ by application type (Python, Ruby, Node.js, Meteor) Document root folder called public/ all static content goes here (images, JavaScript, CSS) Apache configuration…

Python bins fail to import library

Overview A binary (bin) file installed as part of a Python package, e.g. django-admin from Django will fail upon execution – even after successful installation via pip – because it cannot locate its corresponding Python library. Example: [myadmin@sol www]$ django-admin Traceback (most recent call last): File “/usr/local/bin/django-admin”, line 7, in <module> from django.core.management import execute_from_command_line portError: No module…

Disabling Passenger built-in error handler

Overview Passenger provides a user-friendly, on-screen error handler to assist debugging a Python/Ruby/Node.js application. During production, however, this may result in unnecessary and possibly dangerous information disclosure. You can turn off Passenger’s built-in logger and use Apache’s generic error handler by adding the following line to your .htaccess file located within the public/ folder of your app:…

Using WSGI

Overview Python applications can be launched using Passenger offering improved throughput and lifecycle management. Launching CGI scripts wrapped by pyenv will yield very poor throughput as a result of multiple shell subprocesses necessary to ascertain the correct Python interpreter. Adapting a CGI application to WSGI improves throughput significantly by reducing overhead through a persistent process. Pages load quickly, and applications utilize…

Restarting Passenger processes

Overview An application launched by Passenger may be restarted by creating a file in tmp/ (NB: not /tmp) within the application root directory, usually one level down from public/. Create a file under tmp/ named restart.txt to restart the application once. A restart will happen within 2 minutes. To restart an application on every request, very useful for…

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…