Deploying on a VPS
You should now be ready to deploy your Ruby application on a real VPS.
Overview of Popular VPS Providers
There are may VPS providers out there. To help you decide what to choose, we’ll look at three of the more popular providers: Linode, DigitalOcean, and Amazon.
Linode
We start with Linode because it’s a safe bet for many developers: its VPSs are affordable, it has data centers around the world, and it has a fairly good reputation for the past decade.
Pricing and Billing
Linode’s lowest priced server is at $0.015 an hour or $10 for a whole month. This will give you a virtualized server with 1GB RAM, 1 CPU core, and 24 GB of SSD storage, more than enough for serving a small to medium-scale web application.
Linode requires a valid credit card to setup servers, and will be billed at the end of the month automatically. There is a 7-day money back guarantee for new users if you wish to cancel your account early.
Setting Up a Server in Linode
Linode’s Getting Started guide is a good step-by-step walkthrough on setting up your new Linode server. To sync with this book, however, you should use Ubuntu 14.04 LTS instead of the guide’s suggested 12.04 LTS, and you should prefer setting the timezone to UTC; we can always change the displayed time zone under Rails later.
You might have noticed that Linode immediately gives you a root user. To avoid shooting yourself in the foot, create a new admin user with sudo privileges (i.e. the user user in the past few chapters) with the help of the Securing your Server guide. After creating the admin user, you should now be able to continue the steps provided under the Additional Server Setup section. (You should also do the other two steps in the guide, creating a firewall and installing fail2ban, since your server is now publicly available on the internet.)
And that’s basically it for Linode - just follow the steps we did in the previous chapters to deploy your own Rails app on the server. If you’re just planning to use this as a test, don’t forget to destroy the instance as merely shutting down the server will not stop the billing of the instance.
Digital Ocean
Another popular VPS provider is DigitalOcean. A relative newcomer, DO was one of the reasons why VPSs are cheap nowadays. Back in the day when many VPSs were priced at $20 a month, DO came out with $5 VPSs with SSD storage, something unheard of in the low-end server space.
Even though the market has somewhat caught up, DO is still a viable choice for VPS hosting.
Pricing and Billing
DigitalOcean’s $5 server is still available and at 512MB RAM, it should be able to serve small-scale or practice applications. You should go for the higher tiers if you’re deploying applications that have a decent amount of traffic.
Like Linode, requires a valid credit card before you can create a server. One thing DO has that many VPS providers don’t is a PayPal payment option, though this requires you to pre-load credit from PayPal to your account or face monthly Termination Notices.
Instead of a 1 week money-back guarantee, DO has promo codes that give you credit when you sign up. For example, using DROPLET10 will give you $10 of credit. Combined with a valid credit card, this can give the new user 1-2 months of free use (a verification fee of $1.23 is charged to the card but is quickly refunded upon verification).
Setting Up a Server in DigitalOcean
DO has its own Getting Started guide, with the walkthrough at How To Create Your First DigitalOcean Droplet Virtual Server. As with Linode, you should use Ubuntu 14.04 to match the OS used in this book.
DO lets you provide a public key before spinning up the instance of your server. If you do this, DO will perform all of the steps to adding the key (e.g. creating the .ssh/authorized_keys) allowing you to immediately login as root remotely. As with Linode, it’s recommended to create a separate admin user and prevent remote root login. This guide explains the process; it’s similar to Linode’s guide, with the only difference being the command used - gpasswd instead of usermod. The two practically do the same thing so it comes to personal preference (I personally prefer gpasswd).
Configuring the timezone and firewall is detailed in another document. They are somewhat important, but not as important as the section on Creating a Swap File.
Unlike other VPSs, DO “droplets” do not have swap files (where Linux stores its Virtual Memory) configured by default and you should create them manually. So before you proceed with trying to deploy your Rails app on your DO droplet, you must create a swap file which is at least as large as your droplet’s memory (e.g. sudo fallocate -l 512M /swapfile or more for 512MB droplets, 1G or more for 1GB droplets, etc).
Amazon Elastic Compute Cloud (EC2)
An alternative to traditional VPSs would be to use a cloud computing platform to host your entire system. Amazon Web Services (AWS) is a well-known example; not only does it provide virtual machines via Amazon EC2, it also provides online file storage via Amazon S3, content delivery via Amazon CloudFront, scalable databases via Amazon RDS, and so on.
Here we’ll look at Amazon EC2, the VPS equivalent in AWS.
Pricing and Billing
Being part of a cloud platform, Amazon EC2 is billed hourly and thus requires a valid credit card. The pricing is also somewhat complicated, with price differences not only on tiers and types of instances, but also on the location of the data center.
Per dollar, Amazon EC2 instances are more expensive than VPSs with similar specs and performance from other providers. For example, the lowest tier, t2.micro is about as twice as expensive as DO’s $5 tier but can sometimes be slower than the latter. It may not be financially sound for a beginner to use Amazon EC2 for their small to medium-scale applications, especially if their application doesn’t use the other parts of AWS.
On the plus side, AWS provides a free tier for new sign-ups. This lets you use, among other things, a t2.micro instance for 12 months, far longer than the free options from both Linode and DO.
Setting Up a Server in Amazon EC2
Amazon EC2 also has a Getting Started Guide as well as a Setting Up guide for steps to perform before launching a new instance.
Connecting to the instance is slightly different as you cannot remotely log in using passwords or your own public key. Instead, you have to let AWS generate the private-public key pair by following the Create a Key Pair section of Setting Up guide and download the .pem file that you will use to log in later. You should also follow the rest of the Setting Up guide especially the Create a Security Group section which will open the SSH port for remote access.
For practice, choose to create a t2.micro instance running Ubuntu 14.04 LTS and use the newly created “existing” key. After logging in as the ubuntu (not ec2-user which is Amazon Linux’s default user), you can now continue following the steps in the previous chapters to set up your Rails server. You can also copy over your personal public key on a new line at the end of .ssh/authorized_keys if you wish to connect using your own private key.
Note that EC2 instances don’t have swap files by default due to the nature of the default storage (EBS). You can create a swap file by following the steps in DO’s guide, but you should probably not do this since I/O in EBS is billed. If you’re hitting the memory limit, it’s better to get higher tiered instances with more memory or tiers with Instance Store Volumes where you can put a swap file without being charged for I/O.
Setting Up Your Custom Domain
coming soon