Ruby on Rails is best run on a VPS server (if you don’t want to use the likes of Heroku) – typically hosted on one of the various “cloud” providers. Whilst this is pretty standard (and relatively simple to set up), what isn’t simple is the way in which you have to set up the software running on the various VPS boxes you may have.
The truth is that the majority of setting up a VPS server for the likes of Rails is software centric – meaning that the underlying “VPS” is still the same no matter which setup you end up using.
This is why it’s called a “stack” – you’re basically installing various “layers” of the system, from the OS to the underlying libraries to the web server & GIT etc.
If you’re interested in getting your Ruby on Rails application uploaded and running on a “cloud” VPS, you’ll be best placed to look at the various pieces of *software* you’ll require to get it running. This can be done in a number of different ways, but the underlying essentials are still the same. This tutorial is going to explain how to do it…
What’s Required To Get A Rails-Powered VPS Running
The most important thing is to appreciate that this “stack” exists on *ALL* systems – regardless of the operating system or whatever.
The specific software stack you require is as follows:
- Operating System (Linux or Windows)
- System Libraries (OpenSSL, GIT, etc)
- Language Interpreters (Ruby/PHP etc)
- Software Packages (Web Server etc)
- GIT Repo’s + Server Config
The point here is that the above represents the typical “stack” required to get any web server online. Web servers are ALL the same – they are standardized systems designed to provide users with the ability to “publish” HTML pages on the web.
The only difference – and this is especially pertinent with Rails – is that you need what’s known as “application” server software – which represents the “processing” of dynamic requests. For Rails, this is typically “Passenger” but Puma is also applicable.
To understand how this works, I’ll briefly explain the steps required to get it all working…
Installing The Various Software Packages
As mentioned, 99% of the job is installing the different packages.
To do this, you basically let the host set up the server either through their web based interface, or through the API. The API is only really for third party apps, so it’s probably not going to be something you’ll be concerned with.
The point is that everything after that is up to you. Here’s how you do it…
The first thing you need to is gain SSH access to the box.
This is done typically through the provider’s web service (Digital Ocean has a “console” applet for example.This will give you direct access to the server, and you should be able to log in using the “root” username (& password delivered via email).
Create “deploy” User
After you gain initial SSH access, you’re best removing access for the “root” user (to prevent hackers) and change the port to something other than 22. This typically means you have to remember the port – but you need to make sure that you are able to essentially “block” most of the hacking attempts you’ll get.
On top of this, it’s advised you create some sort of “deploy” user. This basically allows you to replace the “root” user and remove reliance on the default settings for the deployment.
Install OS-Level Libraries
After setting up a “deploy” user, you’ll then need to install the various OS-level libraries which will be required to run the various applications.
These will vary depending on which type of application you wish to use – but will typically include most of the same packages.
Install Programming Languages
Install Web Server Software
This will either be Apache or NGinx. Both are supported on all flavours of Linux – and you should be able to get them working on Windows too.
Install “Application” Server Software
After the web server, you’ll need to install the “application” server. This is the program which turns HTTP requests over to the Ruby interpreter – allowing for your Rails app to deliver HTML responses.
For Rails, this will either be Phusion Passenger, or Puma. Setting up either is relatively complicated, so you’ll need to look up how to do it.
Set Up The Various Domains In The Server Config Files
Both NGinx & Apache operate a “virtual host” system – whereby you’re able to “split” the server amongst different domains / apps. By setting them in the config files, you’re able to determine exactly which apps you’re hosting on your servers.
Set up GIT Repo’s
Finally, you need to set up the various GIT repo’s that you may require for your various apps. Whilst you could use a “File Manager” system – or even FTP – to upload files directly, GIT is far more effective at handling versioned uploads.
By doing all of the above, you’ll be able to get your applications deployed to your own VPS servers. Whilst not exhaustive, the above is pretty-much what you need to get it all working.