The 'passenger' command

The passenger command starts or stops a Passenger server in Standalone mode. In this section we will teach you how to use this command.

Table of contents

  1. Loading...

Enter sample app

Ensure that you have prepared a sample application as described in the previous step, and that your command line prompt is inside that directory.

$ cd leaderboard-package/bundle

Starting a server

passenger is the most basic command, and is often used during development. If you have read the 5 minute quickstart then you have already encountered this command. Throughout this basics tutorial, we will encounter this command often.

You begin using Passenger Standalone by starting a Passenger Standalone server. This can be done with the passenger start command.

$ mkdir -p data log && mongod --dbpath data --logpath log/mongod.log --fork
$ export MONGO_URL=mongodb://127.0.0.1:27017/passenger
$ export ROOT_URL=http://0.0.0.0:3000/
$ passenger start --app-type node --startup-file main.js
======= Phusion Passenger Standalone web server started =======
PID file: /Users/phusion/leaderboard-package/bundle/passenger.3000.pid   1
Log file: /Users/phusion/leaderboard-package/bundle/passenger.3000.log        2
Environment: development                     3
Accessible via: http://0.0.0.0:3000/         4

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================

During startup, Passenger prints its runtime parameters to the console. There are several things you see here:

  1. Passenger has created a PID file. The PID file contains the process ID of the Passenger instance, and allows other passenger subcommands to know which process to operate on.
  2. Passenger has created a log file. We will talk about logging later.
  3. Passenger has started your app under the development environment. This means that it has set the environment variable PASSENGER_APP_ENV to the value development.
  4. Passenger is serving your app on http://0.0.0.0:3000/.

If you go to http://0.0.0.0:3000/, you will see your application:

$ curl http://0.0.0.0:3000/
...your app's front page HTML...

All of these parameters can be customized. We will talk about customization later.

Logs

Passenger itself logs things. The application itself may also log things. Here we will describe how logs are handled.

You have learned that Passenger Standalone has a log file. Your application probably logs things to a log file. These are two distinct log files: the Passenger log file is not the application log file.

Your application may also print to stdout or stderr. Passenger also considers these messages as logs.

Passenger handles all of these logs as follows:

  • Passenger's own logs are printed to the Passenger log file.
  • Anything the application logs to its log file, will end up there only, not in the Passenger log file.
  • Anything the application prints to stdout and stderr, are printed to the Passenger log file.
  • Passenger's own logs, the application log file, and anything the application prints to stdout and stderr, are printed to the terminal.

    There is just one caveat here. Passenger can only print the application log file to the terminal, if the log file is named log/<ENVIRONMENT NAME>.log.

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. The second way is by running passenger stop.

Ctrl-C

Let us try out the Ctrl-C method. Go to the terminal where the Passenger server was started, and press Ctrl-C there. You should see that it stops.

# This is what you typed before:
$ passenger start
...

# Now press Ctrl-C:
^C
Stopping web server... done!

'passenger stop'

Let us also try out the passenger stop command. First, start Passenger up again:

$ passenger start

Open a seperate terminal, change the working directory to your application, and run passenger stop.

$ cd ~/leaderboard-package/bundle
$ passenger stop

When you switch back to the first terminal, you should see that Passenger has indeed stopped.

Configuration

Command line options

Most configuration is done by customizing the options passed to the passenger command. For example, you can customize the port that Passenger listens on using --port, and you can customize the location of the log file using --log-file.

Here is an example invocation:

$ passenger start --port 4000 --log-file awesome.log
======= Phusion Passenger Standalone web server started =======
PID file: /Users/phusion/leaderboard-package/bundle/tmp/pids/passenger.4000.pid
Log file: /Users/phusion/leaderboard-package/bundle/awesome.log
Environment: development
Accessible via: http://0.0.0.0:4000/

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================

Many more configuration options are available. You can see all available options by passing --help:

$ passenger start --help
Usage: passenger start [DIRECTORY] [OPTIONS]
Starts Phusion Passenger Standalone and serve one or more web applications.

Server options:
    -a, --address HOST               Bind to the given address.
                                     Default: 0.0.0.0
    -p, --port NUMBER                Use the given port number. Default: 3000
...

Passengerfile.json

Command line options are great for temporarily changing a parameter, but if you want to persist a change, then it is best to store configuration in Passengerfile.json. Passenger Standalone automatically loads configuration from that file if it exists.

The configuration file format is JSON. You can find more information about the configuration file (such as its precedence compared to environment variables and command line options) in the Configuration introduction.

Here is an example Passengerfile.json which customizes the port, log file path and environment name:

{
    "port": 4000,
    "log_file": "awesome.log",
    "environment": "staging"
}

All command line options have a configuration file equivalent. Just omit the initial two dashes --, and replace other dashes - with underscores _.

Next step

Next up we will consider process management, a key feature in Passenger. Process management is what allows Passenger to keep your application stable and to maximize performance.

Continue »