DigitalOcean.com is a website that provide rental server for varies usage, one of those usage they mainly focus on is rails server hosting, with this focus, they provide a dedicated VM setup that came with ruby runtime and rails installed. In DigitalOcean’s term, a server is called a Droplet. In this tutorial, I will take you through the step I took to setup rails server. Some of the steps might be dated, so keep that in mind when you read this tutorial.
Step1-Create DigitalOcean Account:
- Go to DigitalOcean.com
- Click on “Signup”
- Enter required info
- Complete signup
- While in admin page, click “Create Droplets”
- Choose an OS that you wanna VM to run, we tested Ubuntu(Version 16.04.2) and it works as a rails server host.
- In choose a size section, choose the configuration you want for VM.
- Choose a datacenter region, this is where VM physically locate at.
- Click “One-click apps” tab, select Ruby on Rails, this will install Ruby on Rails on VM.
- Leave other field as default, click on “Create”, give DigitalOcean about 60 seconds to setup VM, during this period, DigitalOcean will send you a email contains username and password, you will need to change password in later step.
Step3-Change default root password:
- In admin page, click on the droplet you just created, enter the Droplet admin panel as shown below:
- Click on “Console”.
- To login, enter the username and password that sent you through email.
- After successfully logged in, system will ask you for a new password, type and retype new password.
Option Step-SSH into Droplet:
Although console that you can open through web browser provide you most of functionality that you will need, but you may prefer access Droplet through shell installed on your computer.
- Open a terminal window on your computer.
- Type ssh root@DROPLET_IP_ADDRESS, you can get Droplet’s public IP address from Droplet admin page.
- After login, you will have access to Droplet from your favorite shell.
- You may get some confirmation message, type yes and return.
- If this is not the first time your computer ssh into Droplet and you rebuild VM, you will get a error message, delete corresponding line in text mentioned in error message, try ssh again.
Step4-Git clone Career Raider from bitbucket:
- Open console from droplet admin page
- Run “ssh-keygen” to generate SSH key.
- Rub “cat /root/.ssh/id_rsa” and copy the output.
- Go to your Bitbucket account setting page, add copied key to your account.
- Go back to console, run git clone to clone repository.
Option Step-Adjust Ruby Version
- Run “rvm install DESIRED_RUBY_VERSION” to install ruby with specific version.
- Run “ram use DESIRED_RUBY_VERSION” to use ruby with specific version.
Step 5-Start Rails Server and Tweak Fire Wall
- “cd” into rails project, run “bundle install” and any necessary commands to get database setup.
- Run “rails s” to start server on loopback IP.
- Run “sudo ufw allow 3000” to let fire wall allow traffic through port 3000.
Now, you can go to your browser and access rails website through Droplet’s public IP.