This 5 minute tutorial teaches you to start your application in a Phusion Passenger server, in development mode. Feel what Passenger is and how it works.
Are you looking to deploy your app to production with Passenger, maybe in combination with Nginx or Apache? Take a look at the deployment tutorial.
Table of contents
Loading...
What is Passenger?
Passenger is an open source web application server. It handles HTTP requests, manages processes and resources, and enables administration, monitoring and problem diagnosis.
Passenger is very easy to use, makes deploying in production much easier and is scalable. If you aren't already familiar with the benefits, you can learn more about them.
This tutorial doesn't go very deep into Passenger's concepts. Instead, it serves to get you started as quickly as possible. When you're done with this tutorial, we'll explain the concepts in more detail.
Our apologies to Windows users. Passenger doesn't support Windows. We require a Unix-like operating system.
Limited package support for non-LTS Ubuntu versions
You have selected a non-Long Term Support version of Ubuntu. We only provide .deb packages for non-LTS Ubuntu versions until the next Ubuntu version comes out. Ubuntu versions come out every 6 months.
So when the next Ubuntu version is released, you must upgrade your system to that new Ubuntu version. Otherwise you won't receive Passenger updates in the form of .deb packages from us anymore.
You can install Passenger through APT:
# Install our PGP key and add HTTPS support for APT
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger
sudo apt-get install -y passenger
After installation, please validate the install by running passenger-config validate-install. For example:
$ passenger-config validate-install
* Checking whether this Phusion Passenger install is in PATH... ✓
* Checking whether there are no other Phusion Passenger installations... ✓
If you are using cPanel/WHM, note that it uses EasyApache whereas Passenger RPMs are designed for the official distro Apache. In this setup the gem installation method is likely a better fit, and you should ensure you have the correct apache tools installed: yum remove httpd-tools && yum install ea-apache24-devel. You will also likely need to disable SELinux when using the Passenger gem.
Notes about SELinux on CentOS 7
If you experience dependency errors related to selinux-policy while installing Passenger first try yum clean all && yum update, and if that doesn't resolve the issue, try enabling the CR repo: sudo yum update && sudo yum-config-manager --enable cr.
Notes about SELinux on Red Hat 6 and CentOS 6
Passenger versions prior to 5.1 require kernel >= 2.6.39 if you are installing on Red Hat 6 or CentOS 6 with SELinux set to enforcing mode.
The pre 5.1 Passenger versions can also be installed without upgrading the kernel if you completely disable SELinux. Edit /etc/selinux/config, set SELINUX=disabled and reboot. Note that merely setting SELinux to permissive mode is not enough.
This issue does not apply to Red Hat >= 7 and CentOS >= 7, because these OS versions supply recent enough kernel versions.
You can install Passenger through YUM. But first you need to enable EPEL. The instructions differ depending on whether you are on Red Hat or CentOS. The second step is only necessary on Red Hat.
step 2 (rhel only):
enable the 'optional' repository
enable the optional repository (rhel-67-server-optional-rpms). this can be done by enabling the rhel optional subchannel for rhn-classic. for certificate-based subscriptions see red hat subscription management guide.
Repair Potential System Issues
# Ensure curl and nss/openssl are sufficiently up-to-date to talk to the repo
sudo yum update -y
date
# if the output of date is wrong, please follow these instructions to install ntp
sudo yum install -y ntp
sudo chkconfig ntpd on
sudo ntpdate pool.ntp.org
sudo service ntpd start
After installation, please validate the install by running passenger-config validate-install. For example:
$ passenger-config validate-install
* Checking whether this Phusion Passenger install is in PATH... ✓
* Checking whether there are no other Phusion Passenger installations... ✓
After installation, please validate the install by running passenger-config validate-install. For example:
$ passenger-config validate-install
* Checking whether this Phusion Passenger install is in PATH... ✓
* Checking whether there are no other Phusion Passenger installations... ✓
Extract the tarball to some place permanent. Replace X.X.X with the Passenger version, and /somewhere-permanent with an actual directory path.
$ tar -xzvf passenger-X.X.X.tar.gz -C /somewhere-permanent
Step 2: install Ruby
Passenger supports multiple languages and its core is written in C++, but its installer and administration tools are written in Ruby, so you must install Ruby.
Even though Ruby is required, Ruby will normally not be loaded during normal operation unless you deploy a Ruby web application on Passenger. Passenger's dependency on Ruby is very minimal. See Lightweight Ruby dependency for details.
Again, replace X.X.X with the Passenger version, and /somewhere-permanent with an actual directory path.
When you're done, restart all your shells so that your new PATH takes effect.
Make sure your bashrc is actually included by your bash profile, which might not be the case if you created the user with useradd instead of adduser for example.
Step 4: validate installation
After installation, please validate the install by running passenger-config validate-install. For example:
$ passenger-config validate-install
* Checking whether this Phusion Passenger install is in PATH... ✓
* Checking whether there are no other Phusion Passenger installations... ✓
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:
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: http://0.0.0.0:3000/# =># => You can stop Phusion Passenger Standalone by pressing Ctrl-C.# => ===============================================================
As you can see in the output, Passenger is now serving your app on http://0.0.0.0:3000/. So if you go to that URL, you will should see your application:
curl http://0.0.0.0:3000/
# => your app's front page HTML
Stopping the server
There are two ways to stop the server. The first is by pressing Ctrl-C in the terminal.