Skip to content

Latest commit

 

History

History
147 lines (102 loc) · 3.74 KB

deploying_rails_on_linux.md

File metadata and controls

147 lines (102 loc) · 3.74 KB

Deploying app on Linux/Unix production server

In this guide, you will learn how you can run the app on a linux server together with Passenger and deploy code changes or updates.

Table Of Contents

Deploying app to linux server

  1. Ensure that "passenger" is in the Gemfile.

  2. Login to the server with SSH with your account.

ssh adminuser@yourserver.com

Replace adminuser with the name of an account with administrator privileges or sudo privileges.

  1. Install Git on the server if not installed yet.
sudo apt-get install -y git
  1. Create a directory in which to permanently store your application's code. In this guide, the code will be placed in /var/www/SSID/code.
sudo mkdir -p /var/www/SSID/code
  1. Once done, now pull the code from Git.
cd /var/www/SSID/code
git clone https://github.com/WING-NUS/SSID.git
  1. Install the app dependencies. Since most of these dependencies are gems in your Gemfile, managed by Bundler, you can install them by running:
bundle install
  1. Setup the mysql database inside the server and configure database.yml

  2. Compile Rails assets and run database migrations.

bundle exec rake assets:precompile db:migrate RAILS_ENV=production
  1. Now that we are done with transferring the app's code to the server and setting up an environment for the app, we can start configuring Passenger. Create a Passenger config file
cd /var/www/ssid/code
nano Passengerfile.json
  1. Inside the Passengerfile.json, insert the following:
{
  // Run the app in a production environment. The default value is "development".
  "environment": "production",
  // Run Passenger on port 80, the standard HTTP port.
  "port": 80,
  // Tell Passenger to daemonize into the background.
  "daemonize": true,
  // Tell Passenger to run the app as the given user. Only has effect
  // if Passenger was started with root privileges.
  "user": "appuser"
}

Replace appuser with your app's user account name.

  1. You can now start Passenger. As configured, it will start on port 80 and will daemonize into the background.
cd /var/www/ssid/code
sudo bundle exec passenger start
  1. To ensure that the Passenger Standalone runs on system boot,
sudo chmod +x /etc/rc.local
sudo nano /etc/rc.local
  1. Inside /etc/rc.local, insert the following:
#!/bin/sh
cd /var/www/ssid/code

# Start Passenger Standalone in daemonized mode. 
bundle exec passenger start
  1. You are done. Now, you should be able to access your server.

Accessing app code on the server

  1. Login to the server with SSH. Enter the password given when required.
ssh sadm@ssid-i.comp.nus.edu.sg
  1. Navigate to the directory where the application's code is stored.
cd /var/www/SSID/code

Deploying code changes or updates

Note that unless stated otherwise, all commands should be run on the server, not on your local computer!

  1. Go to your application's code directory on the server, then use Git to pull the latest code:
cd /var/www/ssid/code
git pull
  1. If the application's gem dependencies have changed, install any updated gem dependencies.
bundle install --deployment --without development test
  1. Compile Rails assets and run database migrations.
bundle exec rake assets:precompile db:migrate RAILS_ENV=production
  1. Finally, restart application (so that the updates take effect).
bundle exec passenger-config restart-app $(pwd)