Quickstart: Python + Phusion Passenger



Table of contents

  1. Loading...

What is Passenger?




Install Passenger

Preparing the example application

In this tutorial we will use an example "hello world" application, written in Flask:

git clone https://github.com/phusion/passenger-python-flask-demo.git
cd passenger-python-flask-demo

Adding a WSGI file

What is WSGI?

Many Python web frameworks have a builtin web server that is activated by running the app. For example, you normally run a Flask app with the builtin Flask web server like this:

python app.py

Passenger doesn't work like that. It works with the Python WSGI standard. WSGI defines a standard interface for web applications, allowing any web application that implements WSGI to work with any server that supports WSGI. Pretty much any modern Python web framework implements WSGI. This includes Django, Flask and more.

The Passenger WSGI file

Create a WSGI file in the app's directory. Passenger expects it be called passenger_wsgi.py. The contents depends on the application and the web framework, but for our Flask example app, this is what you need to put in the file:

# passenger_wsgi.py
from app import MyApp as application

What just happened?

WSGI works by defining a callable object called application inside the WSGI file. This callable expects a request object, which the WSGI server provides; and returns a response object, which the WSGI server serializes and sends to the client.

Flask's application object, created by a MyApp = Flask(__name__) call, is a valid WSGI callable object. So our WSGI file is as simple as importing the Flask application object (MyApp) from app.py, and calling it application.

Other Python web frameworks require different code, but work with similar principles.

Running the server

You can now run your app with passenger start:

passenger start
# => ======= Phusion Passenger Standalone web server started =======
# => PID file: /Users/phusion/myapp/passenger.3000.pid
# => Log file: /Users/phusion/myapp/passenger.3000.log
# => Environment: development
# => Accessible via:
# =>
# => You can stop Phusion Passenger Standalone by pressing Ctrl-C.

As you can see in the output, Passenger is now serving your app on So if you go to that URL, you will should see your application:

# => your app's front page HTML

Stopping the server


passenger start
# => ...
# => (press Ctrl-C here)
# => Stopping web server... done!


cd /path-to-your-app
passenger stop


Achievement unlocked. Image taken from https://openclipart.org/detail/60109/award-symbol-by-sheikh_tuhin

Congratulations! You've passed this tutorial and seen Passenger in action. You can find the end result of this tutorial in the example application's git repository's end_result branch.

You may now be interested in intermediate-level tutorial.

Next step

You may now be interested in follow-up tutorials.



Read this


Read this

...or go back to the Library index.