Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rplaurindo/73825d073b139d3001a3aea0061803a4 to your computer and use it in GitHub Desktop.
Steps to deploy a Rails application with Passenger.

Deploying a Rails Application using RVM and Passenger

Instalations (via APT)

Required packages

  • curl
  • gnupg
  • build-essential
  • git
  • nodejs
$ sudo apt install -y <packages>

Ruby

See how to install via RVM (Ruby Version Manager).

Bundler Gem

$ gem install bundler

Passenger and Nginx

$ sudo add-apt-repository "deb https://oss-binaries.phusionpassenger.com/apt/passenger <distribution_name> main"

Or...

$ sudo <file_editor> /etc/apt/sources.list.d/passenger.list

Paste the content deb https://oss-binaries.phusionpassenger.com/apt/passenger <distribution_name> main, save and get out.

Run

$ sudo apt update

And

$ sudo apt upgrade

$ sudo apt install -y nginx-extras passenger

Checking installation

$ passenger-config validate-install

Choose correctly the installation that you want to check and press ENTER.

Settings

Nginx

$ sudo <file_editor> /etc/nginx/nginx.conf

Insert the follow lines

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
include /etc/nginx/sites-enabled/**/*;

To find out when Passenger was installed, run

$ passenger-config --root

Then copy and paste beside passenger_root key.

Creating a Nginx Virtual Server

$ sudo <file_editor> /etc/nginx/sites-available/<environment>/<app_name>

Insert the follow lines

server {
  listen 80;
  server_name = <domain>;
  root <absolute public folder of your project>;
  passenger_ruby <paste ruby interpreter here>;
  passenger_enabled on;
  passenger_app_env <environment>;
  passenger_friendly_error_pages on;
  passenger_start_timeout <seconds>;
}

To set the Ruby version, run

$ rvm use <version>

to find out when the Ruby interpreter is installed, run

$ passenger-config about ruby-command

Create a symbolic link to make the virtual server available

$ sudo ln -s /etc/nginx/sites-available/<environment>/<project_name> /etc/nginx/sites-enabled/<environment>

Restarting the Nginx server

$ sudo service nginx restart

Project

$ git clone <https or git address>

$ git checkout <environment>

Inside the root folder of project, run

$ rvm use <ruby_version>

If the server it’s restarts run this line again, or run

$ rvm --ruby-version use <version>

Like this the Ruby version will definitely be set.

Editing Permissions

$ chmod 700 config db

$ chmod 600 config/database.yml

Gems

Create, inside root folder of your project, the .bundle/config file with the follow content

---
BUNDLE_WITHOUT: "development:test"

To don’t install gems to use in development and tests environment.

So, inside the root folder of project, run

$ rvmsudo bundle install

Note: rvmsudo needs to use only if you isn’t own of the project. Don’t use sudo otherwise the Ruby interpreter will be used from system wide scope, don’t from RVM scope. So create ~/.rvmrc file and put export rvmsudo_secure_path=1 inside this file.

Compiling app assets

$ bundle exec rake assets:precompile

Migrating the database

$ bundle exec rake db:migrate RAILS_ENV=<environment>

Testing deploy

$ curl http(s)://<server_name>

Creating a subdomain error page

server {
  listen 80 default_server;
  server_name *.localhost *.<machine-name>;
  root /var/www/html/errors/404;
  
  # index subdomain.html;
  
  # test like this too
  location / {
  location =/ {
    index subdomain.html;
  }
}

Assuming that exists /var/www/html/errors/404 folder, and subdomain.html files.

Note: no other listener can be a default server, so use default_server only once.

Updating a project

Inside the root folder of project, run

$ git pull

$ bundle install

$ bundle exec rake assets:clean tmp:clear

Compile assets and run migrations

$ passenger-config restart-app

Choose the application and press ENTER.

learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment