How To Deploy Ruby On Rails Applications To Cloud VPS Servers
If you’ve outgrown Heroku’s “free” tier, it’s likely that you’ll want to examine the various ways you’re able to create a private VPS to run any Rails apps you may have.
In order to do this, you should really be looking at the various “cloud” hosting providers (such as Digital Ocean, Linode, etc) who have now started to offer inexpensive VPS hosting onto which you’re able to deploy custom web based applications.
Since Rails is one of the cornerstones of modern web development, it’s important to consider how to set up a private server to run it. It’s actually quite simple.
The most important thing to remember with this is that to set up an HTTP (“web”) server, you ONLY require SOFTWARE to get it working.
The “web” works off the back of TCP/IP (the underlying “protocol” for the “Internet”) – which basically says that if you know the “public” IP address of a computer system, TCP/IP gives you the ability to attempt to “connect” to it.
Each time you “ping” a system, or perform any sort of “handshaking”, it’s done through TCP/IP. This works in both a LAN (Local Area Network) and WAN (Wide Area Network) capacity, providing users with the ability to “connect” to other devices that are “connected” to the Internet.
The problem with TCP/IP is that whilst *every* system that’s “online” can be “pinged”, it cannot be accessed. TCP/IP uses “ports” which basically allow for particular data to be transferred in certain ways – firewall software (which is now built into most operating systems) block access to most ports, to prevent hacking.
The part where HTTP (Hyper Text Transfer Protocol) plays here is that it allows for a “public” set of connectivity – delivered through port 80 (or 443 if using SSL). ANY “HTTP” enabled computer system essentially “opens” a certain folder to the Internet, making it accessible via port 80 of the TCP/IP protocol. This is done with “HTTP” (“Web”) server software.
To run a “web server”, you basically need a computer that’s connected to the “Internet”, has a publicly accessible IP address and is able to accept incoming requests via the HTTP protocol on either port 80 or 443.
This is the beginnings of how you set up a custom VPS server…
Servers Are A Dime-A-Dozen
Thus, anyone with an Internet connection, computer and HTTP server software (NGinx/Apache) can setup a web server.
You don’t even need a domain name – just use your public IP. Domain names are provided by ICANN as a way to make it easier to access web servers – what most don’t know is that a “domain” name simply routes a request to particular IP address. It’s still incumbent on the domain owner & website developer to make that IP accessible to “web” traffic (port 80/443).
The point is that what you pay for “hosting” is really the infrastructure required to keep a server running & operational. “Shared” hosting is basically the ability to buy a “user account” on a HUGE server (used by 1,000’s of websites), whereby the “hosting company” will pay for all the electricity, maintenance and support to ensure maximum uptime.
The problem for most people is that whilst “shared” hosting is a great way to get a simple “WordPress” website online, if you want anything more exotic, you’re at a loss. Specifically, Rails and the likes of NodeJS or other “new” technologies (which require deeper OS integration for their dependencies).
The answer to this (for now) is to set up your own VPS servers. These allow you maximum control over the way in which the server works, and also gives you direct access to the underlying operating system (which means you’re able to add as many dependencies as you want).
To do this, however, takes some setting up. This is done by firstly understanding the core settings / components required to get the server running & online. The following steps will explain how to do this.
Setting Up a Server
- VPS Running Ubuntu
The first step is to get a VPS instance. As mentioned, the best providers of these are the new “cloud” systems such as Vultr, DigitalOcean, AWS, etc. Don’t worry about paying huge money for this – $5/mo is perfect to start with. You also need to use an operating system which is widely supported and not going to add unnecessary expense. Use Linux. You’re never going to look at the server after you’ve set it up, so a costly Windows license won’t matter anyway. Ubuntu is currently the most popular Linux variant. Whilst you could use others, we just recommend Ubuntu for the sake of compatibility.
- Install NGinx/Apache
Next, you need to install the *web* server software. This is what will open port 80 (or 443) to the world, and allow people to connect to the server with their web browser. It must be noted that you’ll also need to install the “application server” with the web server, which typically comes bundled as one package. Both NGinx & Apache have their respective methods of achieving this, which are available on their websites.
- Install Ruby & RubyGems
After you have installed the web server, you need to get Ruby/RubyGems installed. Whilst there are a number of ways to do this, the underlying basis is to build Ruby from source (which requires the build tools) and to install RubyGems on top of it.
- Get GIT Set up
The way you get a Rails application onto the server is with GIT. To get this set up, you need to first download the GIT application (which is done through apt-get), and then add a custom (“bare”) GIT repository on the server. You then need to set up your local repository to handle the GIT remote repo, which should allow you to push to it.
- Push The App & Get Any Extras Set Up
After this, you need to ensure that you are able to push the app to the server via GIT, and then add any extras (such as a database etc). Obviously, how you do this will be dependent on the “stack” setup that you have.
Ultimately, the process is actually quite mundane, and exactly the same as the myriad of “hosting” providers out there.
They just use an application such as CPanel or Plesk to ensure that users are able to “manage” their various features properly.