As we found out the hard way, migrating an old Ruby on Rails project can be a mess.
Here we are going to explain everything step by step, so you don’t have to spend countless hours on it.
First off, let’s mention our assumptions for your project:
- shell access to an Ubuntu 14.04 (or equivalent) server – in case another linux distribution is used, commands might differ
- a LEMP or LAMP environment – this will affect whether you need to setup your reverse proxy with nginx or apache
Ok, first things first. Let’s install rvm development environment:
$ gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ \curl -sSL https://get.rvm.io | bash
$ source /home/admin/.rvm/scripts/rvm
Now, we can install the ruby version we need, in our case 1.8.7:
$ rvm install 1.8.7
* On a newer machine (Ubuntu 16.04) we had trouble installing (because of some openssl incompatibility of 1.8.7) and had to do this in order to install successfully:
Download a patch from here:
We named it ssl.patch.
$ rvm pkg install openssl
$ rvm install –patch ./ssl.patch 1.8.7 –with-openssl-dir=$HOME/.rvm/usr
Next, make sure you are using the correct version:
$ rvm default 1.8.7
$ rvm use 1.8.7
Now, we need to install all gems that are needed by your app plus rails and passenger (in our case, versions 2.3.14 and 4.0.59, respectively):
$ gem install rails -v 2.3.14
$ gem install …
$ gem install passenger -v 4.0.59
Note: If some gems do not install, because of impossible-to-meet dependencies (in our case i18n was not compatible with our old version of ruby), just use the ‘–force’ flag.
Finally, it’s time to start passenger (we will use passenger standalone, because it is more straightforward). From the web application root directory execute:
$ passenger start
Passenger will guide you, if some packages that are needed are missing. Then, you will see the output of the app, so you can fix any issues, if any.
If needed (we faced some issues starting our application, so we had to), switch the rubygems version to the one that was originally used on the web application, which is being moved. In our case this was 1.6.2:
$ gem update –system 1.6.2
You can also start passenger daemonized with the ‘-d’ flag after you make sure everything is working as exppected.
Now you are all done. The only thing you need to do is to reverse proxy from nginx or apache to passenger. We will cover reverse proxying in another post.
Finally, you can have a beer and have a friend tap you on the back for a job well done. Cheers!