Opalstack's 1-click Rails installer sets up the latest version of Rails running on Puma as the backend server, all powered by the system Ruby. This works pretty well for new apps but not so great for old Rails apps that might not be compatible with the system Ruby or for customers who prefer Nginx+Passenger instead of our simpler Puma setup.
Here's how you can get that old Rails app up and running on Opalstack, complete with its crusty old versions Ruby and the entire Nginx+Passenger stack. This procedure will set up the following:
- Ruby 2.0
- Rails 3.2
- Passenger 4
- Nginx 1.0.11
⚠️This is not a one-size-fits-all procedure. If you need a different version of something then adjust the procedure accordingly. This is written to help people get older apps up and running, but you should be able to adapt it to any version of Ruby that's supported by rvm on CentOS7 and whatever it is that you want to run (Rails, etc).
Here we go! 🚀
Log into your Opalstack dashboard and create a new "proxy port" application. Make a note of the application name and port assignment. The rest of this procedure assumes a shell user named myuser
with an app named myapp
assigned to port 55555
.
SSH to your Opalstack server as the app's shell user and install rvm...
gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
- ... then install Ruby 2.00 with rvm ...
rvm install 2.0.0
rvm use 2.0.0
- ... then install the Rails and Passenger gems:
gem install rack-cache -v 1.9.0
gem install rails -v 3.2.13
gem install passenger -v 4.0.2
- Next, download and install Nginx and Passenger. We're using Nginx 1.0 here because it is contemporaneous with the Passenger and Ruby versions that we're using:
mkdir -p $HOME/tmp
export TMPDIR=$HOME/tmp
mkdir ~/apps/myapp/src
cd ~/apps/myapp/src
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar zxf nginx-1.0.11.tar.gz
cd ..
passenger-install-nginx-module --auto --extra-configure-flags=none --nginx-source-dir=$PWD/src/nginx-1.0.11 --prefix=$PWD/nginx
- Upload your Rails project into the app directory
/home/myuser/apps/myapp
. The remaining steps will use myproject
as the project name. If you want to start with a new project for your old Rails app 🤔 then you can make a new Rails project like so:
cd ~/apps/myapp
rails new myproject
# the next line is needed for compatibility with the system sqlite
sed -ie "s/gem 'sqlite3'/gem 'sqlite3', '~>1.3.5'/" myproject/Gemfile
- Next, install your project dependencies:
cd myproject
export LD_LIBRARY_PATH=/opt/lib
bundle install
- Now edit
/home/myuser/apps/myapp/nginx/conf/nginx.conf
to be like the following example. Be sure to change the port 55555 and paths to match your own. If you're not sure about the ruby-2.0.0-p648
version in the example then run env | grep GEM_HOME
to see what rvm
is giving you. Here's the config :
env GEM_HOME=/home/myuser/.rvm/gems/ruby-2.0.0-p648;
env LD_LIBRARY_PATH=/opt/lib;
worker_processes 1;
events {
worker_connections 1024;
}
http {
access_log /home/myuser/logs/apps/myapp/access_myapp.log combined;
error_log /home/myuser/logs/apps/myapp/error_myapp.log crit;
include mime.types;
sendfile on;
passenger_root /home/myuser/.rvm/gems/ruby-2.0.0-p648/gems/passenger-4.0.2;
passenger_ruby /home/myuser/.rvm/rubies/ruby-2.0.0-p648/bin/ruby;
passenger_max_instances_per_app 1;
rails_spawn_method conservative;
passenger_max_pool_size 2;
server {
listen 55555;
passenger_enabled on;
root /home/myuser/apps/myapp/myproject/public;
server_name localhost;
rails_env development;
}
}
- You're ready to start Nginx!
~/apps/myapp/nginx/sbin/nginx
- Now run a quick test on the server to see if it's serving up your Rails app:
curl -s http://127.0.0.1:55555/ | grep -q "riding Ruby ons Rails" && echo success || echo fail
If you got success on the last command then go back to the Opalstack dashboard and attach the myapp
application to a website. You're done! 🎉
If you didn't get success then check the following logs for errors:
You can use the following commands to stop and start the app:
- Start:
~/apps/myapp/nginx/sbin/nginx
- Stop:
pkill -f ~/apps/myapp/nginx/sbin/nginx
That's pretty much it! Just remember to adjust everything for whatever versions you need, install your gems at the correct versions (hopefully handled by bundler), and you should be up and running in no time. 🏃
If you run into any problems or have any suggestions, interesting use cases, etc then please share them here! 🙂