Marcell Purham | Software Developer – Chicago, IL

Fork me on GitHub

Setting up a production server with ruby on rails (Deployment included) Part 1


When first creating a ruby on rails application I thought about going with a service like heroku. Yes heroku is great since they manage your server but the prices and addons can get very expensive. If you’re a developer who is not scared to dive deep into the command line then look no further. In this tutorial I am going to share with you all how to setup your very own production server with rails 3.

What well be using

  • Ubuntu 10.04
  • RVM
  • git
  • Ruby 1.9.3
  • Rails 3.2.4
  • Mysql / Postgresql

What you’ll need

Linode Vps
Rackspace Cloud

Setup server

Now since you are aware of the tools that we’ll be using, lets begin setting up our server from scratch. When you are all signed into your hosting account setup a new ubuntu 10.04 lts(Lucid Lynx) server. If you are using rackspace then I would start with the 256mb of ram(you can scale if needed). After you have picked your server and have setup a root password we will begin logging into the server via ssh and the terminal.

Open your terminal and type root@ your ip address for your server. A prompt should ask if you would like to save key. Yes is the answer.

Now that your logged into the server lets create a new user so that you are not logged in as root for everything. It will ask for you to enter a password for that user. Enter the password then press enter to skip full name etc.

Now that our user account is setup we need to allow our user to install programs but not as root. Open the sudoers file.

Scroll down to bottom and add your username. Press CMD + X & y to save.

Now that we have our user created(though we’re still logged in as root) we can stop people from trying to brute-force our root password and take over out account.

Look for the line that has “PermitRootLogin” and change it from yes to no. Now lets restart the server.

Then logout of your server as root

Now that we are all logged out, lets login using our new user credentials. Connect to the server using ssh

Installing rvm

After successfully logging in as the new user let;s update the software on the server.

Now we’ll install git so that we can install rvm, ruby, and other dependencies that we may need.

Next we’ll install rvm

Then run source so we will not have to exit terminal.

Type code below, if working correctly it will return “RVM is a function”

Now that rvm is setup let’s install ruby dependencies

Installing ruby & rails

Now we’re ready to install ruby. This will take a while

Now set ruby 1.9.3 as default

Ruby is now setup now we will need to install rails. Install the current version of rails at the time of this tutorial rails 3.2.4 is in style :).

Before moving on make sure ruby and rails are installed in that you’re using the correct version and that they are both installed.

Adding a firewall

Now lets install a firewall so we’re not easily venerable to outsiders. For this tutorial I will use Uncomplicated Firewall – UFW, which is a firewall for our ubuntu server.

Now lets setup the rules for our firewall

Now lets check our rules to see if port 22, and 80 are open to the internet

For more information on ufw check out this article, which tells you how to setup a firewall.

In Part 2 of the next tutorial we will setup mysql, apache, and get our web server up and running.

Close
Open