Wednesday, June 4, 2008

Setting up Fast CGI with GoDaddy (fcgi)

Using fastcgi on GoDaddy is paramount to getting any sort of performance with your rails application. If you're not using fast cgi, you will be waiting around 20-30 every time you hit your program with a request. Basically, nothing would work well. Changing your program's settings is as simple as modifying one line in your .htaccess file. First, go to application_name/public/.htaccess and open it in a text editor such at Notepad. Then, change the following line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

This will tell GoDaddy to send requests to Fast CGI, which is much faster. The first request your program gets may take up to 20 seconds, but subsequent requests come at expected speeds. Unfortunately, GoDaddy has the tendency to kill fcgi processes after about 5 minutes, and you might get the occasional error or the speed reduction at this time.

Ruby on Rails Location

One important thing to consider when trying to use Ruby on Rails with GoDaddy shared hosting is the fact that their ruby installation is not in the standard location. As a result, you will have to modify the shebang line to point to the correct spot. The default line is #!/user/bin/ruby, but you need to change this to #!/usr/local/bin/ruby to get any Ruby program to work with GoDaddy. You can find this line in the file application_name/public/dispatch.fcgi or /public/dispatch.cgi. You may want to poke around the /public folder for other places you may need to change it in.

Getting Ruby on Rails Setup

Getting Ruby on Rails setup with a GoDaddy shared hosting account is rather difficult. This blog should hopefully take you step-by-step through the installation process. Remember there are a dozen things that can break a GoDaddy rails setup, which makes installing on GoDaddy's shared servers a pain. Fortunately, though, their low prices can in many cases make up for the extra work, especially if it's a small, personal project with little-to-no budget.

Start by purchasing a GoDaddy shared hosting account, but you probably already have one. If you haven't, though, you'll have to ensure that you have a deluxe or premium account - the basic level accounts don't support cgi, perl, ruby, rails, or any of those things. You can buy three years with 20-30% off, totaling a little more than a mere $100. Remember, though, life would be a lot easier if you can afford your own server, a host that specializes in rails, or a virtual or dedicated server. I'm assuming you're already stuck with GoDaddy.