Install Ruby Rails on Ubuntu Edgy Eft
Posted by Vince Wadhwani on Dec 07, 2006
Update March 05, 2007: Now using gems 0.9.2 by default in this HowTo. To upgrade your older gems see this article.
Update: May 09, 2007: There's now a version for Feisty Fawn!
A while back I wrote a HowTo for installing Ruby on Rails on Ubuntu's Dapper Drake edition. Well, some 6 months later Dapper is still the LTS release but many rails developers are longing to move on to Edgy Eft. While a simple apt-get update && apt-get dist-upgrade will take care of that for most people, it doesn't necessarily help those installing on Edgy Eft from scratch. That being said, the previous HowTo is still accurate. Still, I'm reposting so that people can post their experiences and recommendations (comments are disabled after 20 days to keep spam in check) below. Also, I've cleaned up a few things and removed some older package requirements. Note that this tutorial assumes you did not choose LAMP or DNS server during your install. Probably no harm if you did except we won't be using Apache to run Rails.. we'll be using Lighttpd.
1. Make sure the universe repository in /etc/apt/sources.list is uncommented:
deb http://us.archive.ubuntu.com/ubuntu/ edgy universe
deb-src http://us.archive.ubuntu.com/ubuntu/ edgy universe
Also uncomment the security lines:
deb http://security.ubuntu.com/ubuntu edgy-security universe
deb-src http://security.ubuntu.com/ubuntu edgy-security universe
2. Make sure you are up to date:
sudo apt-get update
sudo apt-get dist-upgrade
3. Install the ruby and mysql base packages:
sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby
4. We need to grab the latest ruby gems from rubyforge. You may need to modify this command if a version after 0.9.2 is available.
sudo wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
tar -xvzf rubygems-0.9.2.tgz
cd rubygems-0.9.2
sudo ruby setup.rb
5. Now let's install Ruby on Rails!
sudo gem install rails --include-dependencies
6. We have Rails but we still need lighttpd. Like the last time, I've thrown in PHP too in case you want to manage your database with phpmyadmin like I do. Repeat after me, apt-get is your friend.. apt-get is your friend: (Thanks to Mitch Golden and Mike McKay for helping scrub this list.)
sudo apt-get install lighttpd php5-common php5-cgi php5-mysql php5-mysqli libfcgi-dev libfcgi-ruby1.8 phpmyadmin
I should mention that there are other popular choices for web server setups such as Apache2 with Mongrel and Pound. Personally, I'm not terribly worried about load balancing and massive scaling at this stage so I skipped it. My understanding is that once Apache2 hits v2.6 that it will no longer require pound in order to interface with Mongrel. At the same time, a bunch of issues with lighttpd are supposed to be solved at v1.5 (they are at 1.4.13 at the moment). I'm going to play wait and see before passing any judgment on my next setup.
7. Modify your /etc/lighttpd/lighttpd.conf file to set up your domains. Be careful because by default Ubuntu maps all the images so that they are taken from /usr/share/images instead of your/rails/root/public/images so if you're wondering why your rails app is working but your images aren't being displayed this is why. You can take out the offending code in your lighttpd.conf or just put your images in /usr/share/images. Here is a sample lighttpd.conf (rename the file and put it in /etc/lighttpd/) for you with the default behavior removed. I'm not a lighttpd expert so please post any corrections/improvements in the comments so I can incorporate them. Update: I would suggest you do not use this lighttpd.conf file until after step 10 else steps 8 & 9 will fail as your app is not set up yet! Thanks to Shinkan and xuehu for pointing this out.
8. Time to enable some modules for lighttpd. There are others that you may need but they should be enabled in your lighttpd.conf. I'm not a fan of enabling modules two different ways but I'm sure this will get cleaned up eventually.
sudo /usr/sbin/lighty-enable-mod fastcgi
sudo /usr/sbin/lighty-enable-mod proxy
sudo /etc/init.d/lighttpd force-reload
9. Let's make sure that there are no errors by stopping lighttpd and then starting it manually:
sudo /etc/init.d/lighttpd stop
sudo lighttpd -f /etc/lighttpd/lighttpd.conf
Update: I don't like it but if you get an error when you try to start lighttpd like: "(network.c.300) can't bind to port: 0.0.0.0 80 Address already in use" then use sudo killall lighttpd to stop lightty instead.
If you have errors there make sure you take a look and try to address them! The output you see will be your best bet in getting help from somebody on one of the forums.
10. Install some basic gems you might need to run your rails app:
sudo gem install actionmailer
sudo gem install activesupport
sudo gem install actionpack
sudo gem install actionwebservice
And now you should have a new, shiny, ready to go Ubuntu Edgy Eft server just waiting for your PHP or Ruby on Rails applications!
To test it out, go to your /var/www/ directory and type sudo rails myrailsapp It should now create a rails app for you in the /var/www/ directory. Next, sure that you have your web app permissions set correctly. You will need to run sudo chown -R www-data:www-data /var/www/myrailsapp to make sure lightty can read the webapp you've created.
Then stop and start lighttpd again to make sure we have no errors:
sudo /etc/init.d/lighttpd stop
sudo lighttpd -f /etc/lighttpd/lighttpd.conf
When you surf over to your server you should see the Welcome to Rails placeholder page waiting for you. Congratulations, that means you've done it right and are ready to roll! The only thing left to do before you get serious is set yourself a root password on MySQL (you can use phpmyadmin for that) and then configure your rails app (/var/www/myrailsapp/config/database.yml) with the correct permissions to use the correct database.
If you are serious about rails development, take a minute to register over at Working with Rails and recommend your favorite rails devs. Good luck and happy coding!
the following command in step 6: sudo apt-get install lighttpd php php5-cgi php5-mysql php5-mysqli libfcgi-dev libfcgi-ruby1.8 phpmyadmin
should be: sudo apt-get install lighttpd php5 php5-cgi php5-mysql php5-mysqli libfcgi-dev libfcgi-ruby1.8 phpmyadmin
xuehu
when I run: sudo lighttpd -f /etc/lighttpd/lighttpd.conf I get the following error message: 2006-12-14 23:42:06: (mod_fastcgi.c.988) execve failed for: /usr/bin/php4-cgi No such file or directory
Should i install php4 instead of php5?
xuehu
Hi xuehu,
Take a look at your lighttpd.conf file and make sure you are referencing php5 instead of php4:
“bin-path” => “/usr/bin/php5-cgi -c /etc/php5/cgi/php.ini”,
Also make sure you have php5-cgi in your /usr/bin
If not it may not have installed correctly. In either case, using php4 is no big deal if you’re just doing rails development and using it for phpmyadmin.
Regarding your first post, I will update my howto: thank you!
vince
There’s a few mistakes I think :
Shinkan
Hi Vince, thanks for the quick reply. I was using your sample.lighttpd.conf, so it was referencing php5-cgi correctly. The php5-cgi is also installed under /usr/bin.
I was able to get rid of the earlier problem by following Shinkan’s suggestion of editing /etc/lighttpd/conf-available/10-fastcgi.conf. But then I run into the following problem: 2006-12-15 21:45:00: (mod_fastcgi.c.979) chdir failed: No such file or directory /var/www/railsapp/public/dispatch.fcgi
which I think is what Shinkan was saying in his third bullet.
So I skipped to step 10 and created a rails app with the name of “myrailsapp”. I then try to start lighttpd but still got the same error. To fix this I have to edit the lighttpd.conf file and change the reference to “/var/www/myrailsapp/public/dispatch.fcgi”.
Then lighttpd started with no error messages!
But I don’t get a Welcome to Rails placeholder page, only a welcome to lighttpd page. If I go to http://localhost/myrailsapp. I got a directoy listing. Is this normal? As you can guess, I am totally new to ruby, php and lighttpd.
Also, there is a type in the sentence: “Next, (make) sure that you have your web app permissions set correctly. ”
xuehu
Shinkan: I do see that you can edit the /etc/lighttpd/conf-available/10-fastcgi.conf and change php4 to php5. This wasn’t required for me to get phpmyadmin working but you make a good point and so people should do that as well just in case their experience differs.
xuehu: Thanks for going through this and spotting the lighttpd error with Shinkan. I’ve updated the howto accordingly.
With regards to your problem, you will need to make sure that your lighttpd.conf is pointing localhost to your rails app folder. Right now it’s set to point www.railsapp.com to the right folder. Since you accessing as localhost you will have to change that line to $HTTP[“host”] =~ “(^|.)localhost”
I’m mostly using webrick for local rails development which makes it simple and then reserve my lighttpd setup for my server.
Hope that helps..
vince
These instructions still have problems. It’s not the inclusion of the php5 on the same line with lighthttpd that causes the apache2-common to be installed, it’s that if you install package php5 rather than package php, apache2-common will be installed. You should actually revert the instructions to apt-get install php which gets you php5 anyway, but without apache2-common
Mitch Golden
Mitch - I am not seeing a php package, but I am definitely having the problem with apache2 trying to install itself. My solution was to: apt-get install libfcgi-dev libfcgi-ruby1.8 phpmyadmin
phpmyadmin forces the php stuff to get installed and doesn’t install apache. We’ll see if it actually works…
Mike McKay
I kept getting an error running php pages, edited my /etc/lighttpd/conf-available/10-fastcgi.conf
#
fastcgi.server = ( “.php” => (( “bin-path” => “/usr/bin/php5-cgi”, “socket” => “/tmp/php.socket”, “max-procs” => 2, “idle-timeout” => 20, “bin-environment” => ( “PHPFCGICHILDREN” => “4”, “PHPFCGIMAX_REQUESTS” => “10000” ), “bin-copy-environment” => ( “PATH”, “SHELL”, “USER” ), “broken-scriptfilename” => “enable” ) ) )
cas27
Mitch, Mike:
I could have sworn there was a php package at the point I first wrote this HowTo but now it seems to be gone:
Reading package lists… Done Building dependency tree
Reading state information… Done E: Couldn’t find package php
I agree that it would be preferable to use the metapackage by default which just grabs php5 without apache.
vince
Thanks for a very nice explanation on how to deploying ROR on lighttpd on linux.
Are there any links on customizing lighttpd.conf for specifically for ROR around the net, please post them, as I have trouble on setting this up on port 3000, folder /var/rails/. I get standard listing, and have tried all descriptions above.
joakimcs
You should take a look at the lighttpd forums for lighttpd specific help. But one classic problem is that people forget to remove the default index.html file from their app directory.
So if you’ve got an index.html file in your /var/rails folder make sure you remove it otherwise your rails app might not work.
You can also take a look at the postfix on edgy article on this site.. there’s a different lighttpd conf which has some rails specific stuff documented but commented out.
vince
I see that the php meta-package seems to have disappeared. Maybe it’s best simply to recommend the installation of the various packages you actually need, namely php5-common php5-cgi php5-mysql and php5-mysqli
Mitch Golden