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-nodejs-connect-demo.git
$ cd passenger-nodejs-connect-demo
$ npm install
Running the server
The simplest way to run your app is with the node command:
$ node app.js
Passenger can be used the same way as the node command: you run your app with passenger start and two extra command line options:
$ passenger start --app-type node --startup-file app.js
======= 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.
===============================================================
If you run your app with a higher level command like npm start, you can find out what --startup-file to specify by looking at package.json. It should be whatever is behind the node command.
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...
Passenger is polyglot
Passenger supports apps in multiple programming languages. That's why you need to specify what language you're using.
The --app-type node option does just that.
Reversed port binding
Normally, a Node.js app binds a server socket on a certain port by calling listen() on an http.Server object. But when run in Passenger, this control is inversed. The user that invokes the passenger command specifies what address and port to listen on, and Passenger makes sure your app does so.
Most of the time, reverse port binding just works. But if your app creates multiple http.Server objects, then you will confuse the reserve port binding system, and you'll have to give it some hints.
Passenger prints its own logs not only to the terminal, but also to a log file. During startup, Passenger tells you what log file it used. This is typically passenger.XXXX.log.
There may also be application logs, generated either by your app or by the framework you're using. These logs are completely separate from Passenger's own logs. If the application logs are printed to stdout or stderr, then Passenger will display them. Otherwise, it is up to you to manually view application log files, e.g. with the Unix tail tool on the corresponding files.
Stopping the server
If you stop Passenger, Passenger will stop your app.
There are two ways to stop the server. The first is by pressing Ctrl-C in the terminal.