Comments Off

A buddy asked me this week about deploying a Rails app on Linux and my response was close to “life is like a box of chocolates…”

Losing my Linux foo seems to be a side effect of becoming Windows stupid because of .NET and MSSQL at work. I try not to be a hater, but Windows makes it really, really difficult to avoid (and I still think the iPad blows). Losing my foo == Unacceptable.

So, today, after shoveling 4 inches of snow off of the walk while wearing flip-flops; I played the ‘tard card and sat down to build a Ubuntu server with Ruby, Rails, Mysql, and Mongrel. Here’s how to give it a go.

Ubuntu Server Version 9.1 running on a VM.
Mysql Version 5.1.37
Ruby 1.8.7
Rails 2.3.5
English Breakfast Tea (Optional)
SSH
Navicat on OS X (also optional, but I do like a GUI to manage DB’s)

Keep in mind that I’m running Ubuntu on a NAT’d VM as a dev environment, not a production environment, so security really isn’t all that much of a concern (especially on the DB side).

Step one:
Downloaded ubuntu-9.10-server-i386.iso and did the requisite VM installation. This one is a no brainer, so this is all you get on it. It’s a barebones server version, no KDE or Gnome. Make sure you set it to NAT, you don’t want bridged, especially if you hit coffee shop wifi networks all the time.

Step two:
Installed SSH server from the VM Console:

sudo apt-get install openssh-server

if you want the client (I don’t think it’s necessary), append the following to the above:

openssh-client

Step three:
SSH into the NAT’d VM from Terminal (or putty for the Windows challenged, or whatever SSH client you want)

ssh -l sisboombah 192.168.208.131

where -l passes the username “sisboombah” and the ip is the NAT’d VM. If you’re scratching your head trying to figure out the IP of the VM, log into Ubuntu via the VM console and type:

ifconfig

The results passed back will look like this and you’re looking for the inet addr:

eth0      Link encap:Ethernet  HWaddr 00:0c:29:40:3b:d6
inet addr:192.168.208.131 Bcast:192.168.208.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe40:3bd6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:25371 errors:24920 dropped:0 overruns:0 frame:0
TX packets:13611 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32636426 (32.6 MB)  TX bytes:967437 (967.4 KB)
Interrupt:19 Base address:0×2024

Step 4:
English breakfast tea
Boil some water, cover the bottom of a really large mug with honey (Orange Blossom is my choice), pour boiling water over the honey. Drop two teabags in. Let steep for 3-5 minutes. Flavor with Stranahan’s. Add a little milk or half and half.

Alternate method:
Exclude all but the Stranahan’s and add four ice cubes.

Drink.

Step 5:
Install Ruby and Rails:
sudo apt-get install ruby rubygems ruby1.8-dev libsqlite3-dev libopenssl-ruby mysql-server libmysql-ruby build-essential && sudo gem install rails sqlite3-ruby

You get sqllite and mysql here. Make sure you write down the Mysql root password when prompted. If you don’t and you forget it, reinstalling the VM is the best way to go. Since ruby is installed via the package management system, it requires a tweak. Namely, you need to alter your path for gems to work properly. You could use vi to do this, but nano isn’t nearly as much of a pain in the butt (we could fight about editors all day, just give this one a pass):

sudo nano /home/sisboombah/.bashrc

for the ‘tards, “sisboombah” needs to be replaced by your username on the Ubuntu box. Add this to the file:

PATH=”$PATH:/var/lib/gems/1.8/bin”

If your foo is weak, back this file up before you make the change so you don’t Roger yourself roundly; although if you do, it’s a VM, you can always reinstall, so who cares?

Step 6:
Get Mongrel. You could really do this in step 5, but what the hell.

sudo gem install mongrel

Step 7:
Treat mysql like the unsecured biatch it needs to be in a development environment. It installs itself in lockdown mode, we need to remove pretentious things, like any myth of being secure:

Edit the mysql my.conf file to allow connection from your workstation. You want to add a line to allow connections from your IP address. Open the file with Nano to edit:

sudo nano /etc/mysql/my.cnf

to this:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1

add this:

bind-address            = 192.168.208.131

Where 192.168.208.131 is the IP address of the Ubuntu box.

Use ifconfig on the Ubuntu VM to get the IP if you’ve had too much English Breakfast tea.

Next, we need to blow out the security settings to grant all access to everything in Mysql to a user. “But it’s not secure!” Of course it’s not, this a development environment running NAT’d. If you are really a ‘tard and your base OS is already full of holes, not really my problem.

Log in to mysql on the Ubuntu box:

mysql -u root -p mysql

If you forgot the mysql root password it is probably easier to either uninstall mysql via apt-get or just rebuild the vm. If you did forget the password, an English Breakfast Tea break is recommended, or if you’ve already had one, maybe coffee is in order.

In mysql, we need to grant all privileges on everything to a user. And yes, again, this guts security and is not “best practices” for an outward facing server. Again, this is for a dev environment.

grant all privileges on *.* to sisboombah@192.168.208.1 identified by ‘supersecurepassword’;

again “sisboombah” is your username, “192.168.208.1″ is the IP you are connecting from (in this case the ip of the machine hosting the VM) and “supersecurepassword” is the password you will access mysql with, I recommend using “a” .  :-P

Now, let’s restart the Ubuntu box since we’ve altered all kinds of stuff:

sudo shutdown now -r

From your “remote” system, you will be able to connect to mysql with your favorite client.

You should now have a fully functioning dev stack on the VM, woot.

If the English Breakfast Tea is pumping your ego and you want to further pretend you’re Linus Torvalds, you can add git:

sudo apt-get install git-core

Although, come to think of it, he would build from source after reviewing the code.

More is available on the installation here:

More info on the installation

A side note, I’m now #1 on Google for “jelly ssh” and “ssh jelly”. Talk about bragging rights! If only I could find a market that would pay for ssh jelly, we all know it lubricates the canuter valve Ubuntu depends on for network services and makes ssh so much faster.

Comments are closed.