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.
- Deploying app to linux server
- Accessing app code on the server
- Deploying code changes or updates in the server
-
Ensure that "passenger" is in the Gemfile.
-
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.
- Install Git on the server if not installed yet.
sudo apt-get install -y git
- 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
- Once done, now pull the code from Git.
cd /var/www/SSID/code git clone https://github.com/WING-NUS/SSID.git
- 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
-
Setup the mysql database inside the server and configure database.yml
-
Compile Rails assets and run database migrations.
bundle exec rake assets:precompile db:migrate RAILS_ENV=production
- 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
- 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.
- 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
- To ensure that the Passenger Standalone runs on system boot,
sudo chmod +x /etc/rc.local sudo nano /etc/rc.local
- Inside
/etc/rc.local
, insert the following:
#!/bin/sh cd /var/www/ssid/code # Start Passenger Standalone in daemonized mode. bundle exec passenger start
- You are done. Now, you should be able to access your server.
- Login to the server with SSH. Enter the password given when required.
ssh sadm@ssid-i.comp.nus.edu.sg
- Navigate to the directory where the application's code is stored.
cd /var/www/SSID/code
Note that unless stated otherwise, all commands should be run on the server, not on your local computer!
- 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
- If the application's gem dependencies have changed, install any updated gem dependencies.
bundle install --deployment --without development test
- Compile Rails assets and run database migrations.
bundle exec rake assets:precompile db:migrate RAILS_ENV=production
- Finally, restart application (so that the updates take effect).
bundle exec passenger-config restart-app $(pwd)