INCLUDE_DATA

Up and running with Ubuntu, Ruby on Rails, thin, Nginx from scratch

My current most favourite hosting company is slicehost. When I start a new slice, I choose Ubuntu and get a shiny new virtual server with the default Ubuntu installation. Starting with that default installation, this step-by-step guide will give you a secure server with all the goodies mentioned above.

This example here is using Ubuntu 8.04.

1. Update your distro

sudo apt-get dist-upgrade

2. First things first, secure the server
ssh config:

sudo vi /etc/ssh/sshd_config

This is what I recommend:

  • Port: change to some port above 9000. That makes it just a bit more difficult to probe the server.
  • PermitRootLogin: change to no. You don’t ever want to login as root anyway. Login as a user and sudo instead.
  • LoginGraceTime: change to 20. That should be more than enough time for anyone to login.
  • RSAAuthentication: change to yes, so that you can use password-less logins using keys (nice when using Capistrano)
  • AllowUsers: you need to add this setting. Add account names of accounts that are allowed to login. Only users listed here will be able to login. Highly recommended.

Next, restart the ssh daemon, and test that you can still login. DO NOT LOG OFF UNLESS YOU HAVE TESTED THAT YOU CAN LOGIN FIRST :D. So, while still logged in, open another terminal and type:

ssh -p port_that_you_chose_above username@servername_or_ip_address

If all’s good, ssh configuration is complete.

Bastille Linux
This little gem is one of the most useful I know. It ensures that your server’s security is nice and tight.

sudo apt-get install bastille
sudo InteractiveBastille

Now just follow the instructions one by one, answering one question at a time. Make sure you also answer the firewall questions, and to enable it. When it’s all said and done, you’ll have a nice secure server.

3. Install build-essentials, and linux headers
We’ll need to be able to compile things, so we need this package. Note: some people believe that installing compilers on a production machine is an insecure practice, as it allows a potential hacker to compile their own attack binaries on the machine. If this is the case for you, do not install the package, and compile the binaries on another machine, then copy them to the proper locations on your production machine. We will be tightening security pretty nicely, so it is my opinion that this is not a big deal.

sudo apt-get install build-essential
sudo apt-get install linux-headers-

4. Now, let’s start by installing ruby and rubygems

sudo apt-get install ruby
sudo apt-get install rubygems

To be continued …

Upgrading to Rails 2.1 RC1 (with HAML)

Good morning one and all. Here is a step-by-step transcript of how I got my project from Rails 2.0.2 to 2.1 RC1.

1. Remove Rails 2.0.2 from the project and the svn repo:

svn rm vendor/rails
svn commit vendor/rails -m "[REMOVED] Rails 2.0.2 from repo;"

2. Checkout Rails 2.1 RC1 from the git repository, and then move to the 2.1 RC1 branch:

cd vendor
git clone git://github.com/rails/rails.git
cd rails
git checkout v2.1.0_RC1

3. Start the server:

I’m using HAML, so I got this error:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
Exiting
/opt/local/lib/ruby/gems/1.8/gems/haml-1.8.2/lib/haml/template/plugin.rb:42: undefined method `register_template_handler' for ActionView::Base:Class (NoMethodError)
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
	from /Users/aeldaly/Documents/clients/code/new_moredating/vendor/rails/activesupport/lib/active_support/dependencies.rb:508:in `require'
	from /Users/aeldaly/Documents/clients/code/new_moredating/vendor/rails/activesupport/lib/active_support/dependencies.rb:353:in `new_constants_in'
	from /Users/aeldaly/Documents/clients/code/new_moredating/vendor/rails/activesupport/lib/active_support/dependencies.rb:508:in `require'
	from /opt/local/lib/ruby/gems/1.8/gems/haml-1.8.2/lib/haml/template.rb:28
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
	 ... 44 levels...
	from /Users/aeldaly/Documents/clients/code/new_moredating/vendor/rails/activesupport/lib/active_support/dependencies.rb:508:in `require'
	from /Users/aeldaly/Documents/clients/code/new_moredating/vendor/rails/railties/lib/commands/server.rb:39
	from ./script/server:3:in `require'
	from ./script/server:3

A quick search on google, led me to this post: http://nex-3.com/posts/76-haml-2-0

So, I proceeded to update to HAML 2. Here goes:

sudo gem update

It updated quite a few gems, and yes, one of them was indeed HAML 2.0.

4. Start server, take 2
No errors!! You should now be running on Rails 2.1 RC1. Congratulations.

5. Commit to svn:

svn add vendor/rails
svn commit vendor/rails -m "[UPDATED] app to Rails 2.1 RC1"

ActiveRecord callbacks in specs?

While writing specs for my models, I sometimes found them failing for no apparent reason. After a bit of investigation, I found that my callbacks in the models where not being called. My solution? I call them myself, like so:

it "should set profile flag" do
  @photo.send(:before_create)
  @photo.save
  @photo.profile_pic = true
  @photo[:options][:profile_pic].should be_true
end

I find that this is a problem only with before_create and not with after_create. Not sure why this is hapenning, but this is waht worked for me.

Yippee Kay Yeah!

New design fordevelopergurus.com and for blogs.developergurus.com. I think they’re both pretty nice, and it’s all made by yours truly, and based on the copyblogger theme by Chris Pearson. The nice thing about them, in my opinion is that they are leveraging wordpresses awesome customisation potential. developergurus.com is being powered by the same css as the blog.

I used CSSEdit to make all the modifications and it was a pleasure to use. This program made it really fun to put the CSS together.

What’s planned for this blog? Well, big things I hope. I will strive to make this a blog filled with pertinent information to the developer community in general and the Ruby on Rails community in less general terms. Time will tell how well I reach this goal.