Introduction

So before my monstrous OpenSolaris 2008.05 post on setting up a Ruby on Rails server I decided to write a guide on setting up a Ubuntu 8.04 server guide for all you Slicehost users! I decided to write this guide because of the new optimized kernel that was added to Ubuntu Server 8.04 for virtualized environments. I also wanted a complete guide that would be a solid reference and now just have bits and pieces for upcoming sysadmins will get lost when reading.

For simplicity I will start with a black machine and build upon that. Use the comments section for specific questions or starting points. I will try to do my best at answering any and all questions.

Requirements

This section will go over the simple requirements of the entire setup.

Hardware

Ubuntu 8.04 Server - This could be anything below:

  • Slicehost
  • VMware
  • Bare Metal Install

Software

  • Apache 2.2.8
  • MySQL/PostgreSQL/SQLite3
  • Git
  • Ruby
  • Rubygems
    • Rails
    • Capistrano
    • RSpec
    • Passenger

Installation of Software

First thing before we start installing anything on this machine we must update the server. This is very simple with Ubuntu, it is two simple commands and you are all set. You only need to reboot the machine if a kernel was installed.


sudo apt-get update
sudo apt-get dist-upgrade

Now that the machine is updated we must install some essential tools in order to build software on this server. Once we are done with the setup it would be a good idea to remove these tools to increase security on our server.


sudo apt-get install build-essential

Now we are all set with the preparation of the server and we can start installing the software we need to get going.

Web Server

For the web server I chose to use Apache 2 because of the new Passenger gem or (mod_rails). This gem is great because of the simplicity to deploy new applications.


sudo apt-get install apache2 apache2-threaded-dev

Database Server

The database server that should be used is completely up to your preference. My recommendation is PostgreSQL. PostgreSQL is a very robust and fast database server that is rock solid. It does use a lot of resources so for Slicehost it may not be the best choice. A major player for a slim and fast database for Slicehost should be SQLite3. It is a wonderful database and should be thrown out so quickly because of its lack of a client/server architecture.

For this tutorial I will install MySQL because of its popularity with the Rails community.


sudo apt-get install mysql-server mysql-client libmysqlclient15-dev

When prompted enter a root password, make this complex and write it down.

Version Control

Git is the most sexy version control system every created. I will never look back to subversion again. Now that capistraon and redmine both support git I have no reason to even thing about those awful three letters.

To install git is yet another apt-get command away. Run the following command in the terminal of your new server.


sudo apt-get install git-core curl gitweb

gitweb is an optional web frontend for your applications. I do not use it because I use GitNub a RubyCocoa application for the Mac.

Once that finishes git is completely installed and ready to go.

Ruby

Installing Ruby on Ubuntu 8.04 is quite simple. Just another apt-get and you are all set... almost. Since the inception of Ruby 1.9.0 distributions have been naming the current stable release of ruby "ruby1.8" That being said we will make a couple symlinks.

Ruby 1.8.6

To install all the tools you will want on this server run the following command:


sudo apt-get install ruby rdoc ri irb libopenssl-ruby1.8 ruby1.8-dev

Rubygems

I refuse to install Rubygems with apt-get. This is such a terrible idea in my opinion. There is no reason to install rubygems with a package manager because it can update itself. I will go over how to update rubygems later in this howto.


cd /usr/local/src/
sudo wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
sudo tar -xzf rubygems-1.2.0.tgz
cd rubygems-1.2.0
sudo ruby setup.rb

Optional: Once you are done with install just run the next three commands to make using gems and Rubygems just as before.


sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Recommended Gems

Here is a list of recommended gems that should be installed once rubygems is installed. At the very least you must install rails and passenger.


sudo gem install rails capistrano rspec passenger mysql rdoc

Part Two

Next week I will go over how to connect all the pieces together and get a sexy Ruby on Rails server running smoothly. I will go over configuring git on your local computer as well as setting up passenger and capistrano to function with all of the above sexy applications we just installed.

23 Responses to “Ubuntu 8.04 Rails Server Using Passenger”

  1. Piku Says:
    Nice post, i'll be glad to hear your guide and thoughts on OpenSolaris. Just a small typo: it's 'sudo gem install capistrano'
  2. Scott Becker Says:
    Cool. Following along. Noticed another typo: URL to rubygems should be: http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
  3. Scott Becker Says:
    Should also run "sudo apt-get install apache2-mpm-prefork" or passenger is going to complain when you run "passenger-install-apache2-module"
  4. Ron Valente Says:
    Piku, Glad you liked it, thanks for the fix. Scott, Worker is more friendly to hosted environments like slicehost. Worker is not officially tested but deemed ok for use with Passenger.
  5. meekish Says:
    Can you explain what makes mod_worker better for a VPS? I have some PHP apps on my server and am hesitant to ditch mod_php for mod_fcgid.
  6. meekish Says:
    I Googled and found this article: http://doughboy.wordpress.com/2008/02/13/apache-worker-and-php/
  7. rockmanx.wordpress.com Says:
    Thanks man! I did it thanks to you... luck you mayts!
  8. Ron Valente Says:
    I am glad to see everyone's success so far with this server setup. I am almost done with the second part of the guide. -Ron
  9. gaw.in Says:
    Gitweb does not install correctly:
    apt-get install git-core curl *gitweb*
    Result:
    E: Regex compilation error - Invalid preceding regular expression This can be fixed by splitting up the command to:
    apt-get install git-core
    apt-get install gitweb


    OR just combine the command:
    apt-get install git-core gitweb

    *Don't forget to sudo ;-)*
  10. gaw.in Says:
    **Rubygems**
    First setup the symbolic links, and then run the *ruby setup.rb* Otherwise it would not find ruby. If running *setup.rb* gives you errors, try running it with *sudo* privileges.
  11. Si Says:
    Dont' forget sudo gem install mysql
  12. Sam Says:
    At the start: Shouldn't it be: >sudo apt-get update >sudo apt-get dist-upgrade and not... (note "install") >sudo apt-get install update >sudo apt-get install dist-upgrade
  13. Ron Valente Says:
    @ Sam, Si, and Gaw.in Thanks for the updates... when I wrote *gitweb* i was referring to the note below. That was my mistake not making that clearer. I will make the updates now. -Ron
  14. Jeff Says:
    I'm trying to run through this with the latest ubuntu setup... I'm getting this error when I try to install the mysql gem. Any ideas? $ gem install mysql Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb install mysql checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... yes checking for mysql_query() in -lmysqlclient... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
  15. Jeff Says:
    I was able to solve my problem by running: apt-get install libmysqlclient15-dev
  16. Mathieu Martin Says:
    For those who might like to do it through SSH instead of directly on said machine (e.g. for a fresh install): On the server: sudo apt-get install openssh-server On the client: ssh username@serveraddress
  17. icebreaker Says:
    Re: sudo apt-get install apache2 apache2-dev. It seems it is necessary to replace the last part with: apache2-threaded-dev
  18. part 3? Says:
    what happened to part 3?
  19. ? Says:
    at least on 8.04 JeOS ubuntu doesnt come with gem's demendency rdoc--took me a which to figure this out
  20. ? Says:
    and wget or tuby 1.8 i guess its quite trimmed
  21. JC Says:

    Thanks for the post. I followed along with a default Ubuntu 8.04 server. I ran into problems with the sudo ruby setup command. You can see the error below. I couldn’t find anything on the web. Maybe you can give me some clues on how to fix this problem.

    jc@ubuntu:/usr/local/src/rubygems-1.2.0$ sudo ruby setup.rb /usr/lib/ruby/1.8/rubygems/defaults/operating_system.rb:25: undefined local variable or method `user_dir’ for Gem:Module (NameError) from ./lib/rubygems.rb:772:in `require’ from ./lib/rubygems.rb:772 from setup.rb:22:in `require’ from setup.rb:22

  22. Ron Valente Says:

    What shell are you using? Seems as though you are missing an environment variable. I have not come across that problem before. If you have any more information about your environment it would be a great help.

    As long as you have ruby installed correctly you should be able to install rubygems no problem. If that doesnt work for you via source then just use the ubuntu Rubygems package.

    sudo apt-get install rubygems

    Let me know if you have any more questions. -Ron

  23. smogiliorge Says:

    nice work, bro

Leave a Reply