Fedora 7 guide to installing Ruby on Rails with Mongrel in a development enviroment

May 31st, 2007

Fedora 7

This is a very basic guide to getting Ruby on Rails running with Mongrel in a development enviroment. If you don’t have much experience with Linux or Fedora this guide should be step-by-step with a default installation.

Become root first::


$ su -
# yum install ruby ruby-rdoc ruby-irb ruby-ri ruby-doc
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
# tar xvfz rubygems-0.9.4.tgz
# cd rubygems-0.9.4
# ruby setup.rb
# cd ..
# rm -rf rubygems*

Be careful with this, as it will delete everything that starts with rubygems in this directory recursively.


# gem install rails --include-dependencies
# yum install ruby-devel mysql mysql-devel mysql-server
# service mysqld restart
# mysqladmin -u root password '(passwd')
# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

I chose Mysql 2.7; you’ll need to do some coaxing to install Mysql 2.6 correctly.

Drop out of root:


# exit
$ nano /(path to RoR project)/config/database.yml

Your database.yml should look like this. Replace the database name with your db, your username, password, etc:



development:
adapter: mysql
database:
username:
password:
host: localhost
socket: /var/lib/mysql/mysql.sock


test:
adapter: mysql
database:
username:
password:
host: localhost
socket: /var/lib/mysql/mysql.sock


production:
adapter: mysql
database:
username:
password:
host: localhost
socket: /var/lib/mysql/mysql.sock

Get back into root:


su -
#gem install daemons gem_plugin mongrel mongrel_cluster

You’ll get this long string of text:


Successfully installed daemons-1.0.6
Installing ri documentation for daemons-1.0.6...
Installing RDoc documentation for daemons-1.0.6...
Successfully installed gem_plugin-0.2.2
Installing ri documentation for gem_plugin-0.2.2...
While generating documentation for gem_plugin-0.2.2
... MESSAGE: Unhandled special: Special: type=33, text="Implements"
... RDOC args: --ri --op /usr/lib/ruby/gems/1.8/doc/gem_plugin-0.2.2/ri --quiet lib README
(continuing with the rest of the installation)
Installing RDoc documentation for gem_plugin-0.2.2...
Select which gem to install for your platform (i386-linux)
1. mongrel 1.0.1 (mswin32)
2. mongrel 1.0.1 (ruby)
3. mongrel 1.0 (mswin32)
4. mongrel 1.0 (ruby)
5. Skip this gem
6. Cancel installation
> 2
Install required dependency fastthread? [Yn] Y
Select which gem to install for your platform (i386-linux)
1. fastthread 1.0 (ruby)
2. fastthread 1.0 (mswin32)
3. fastthread 0.6.4.1 (mswin32)
4. fastthread 0.6.4.1 (ruby)
5. Skip this gem
6. Cancel installation
>1


Drop back out of root:

# exit

I chose the latest versions. Watch out for incompatible versions.

You should be done. Edit your project and then start mongrel:


mongrel_rails start /(path to project)/


I’m just using this for a development system, I’ll add more once I start playing around with deployment.

Speeding up your app

February 22nd, 2007

More and more rails apps are going wild. I’ve been using things like Backpack and Wesabe for awhile now, and I wonder what they are doing for optimization. Some actions really seem to take forever, but as a bystander it’s impossible to tell how much of that is due to traffic and how much is due to possibly inefficient coding. Regardless, as these types of programs get more use by normal people, they will have to be sped up.
Over the course of the last two months, I have been focusing on improving the speed of our rails applications. We (at LoyInc, not e4 industries) built a massive database management system that’s being used by the National Forestry Service as well as the University of Wisconsin-Madison Biostatistics department. This system is also being used by a network of radio stations (where I also work… it’s complicated :) ). Anyway, the dbms basically acts as a back end for all of the websites for the radio stations. It serves queries as XML feeds to the websites, where the data is parsed & made pretty. At the beginning of this process, these data feeds ran at a ridiculously slow 3-5 requests per second. (Zed, sorry about the seat-of-the-pants statistics, if you ever read this.) After a month of tweaking, the same queries run at 480-500 requests per second.

What’d I do?
1. Only select the fields I needed from each query within my runQueryAsXML action

2. Turning off sessions for that specific action (they’re public queries, no session needed)
3. Providing as many url params as possible — making extra lookup queries unnecessary.

4. Reusing results of internal queries

These all pretty much sound obvious, *but* most people do silly things like repeat queries and grab the same associations over and over within an action. Get the hash for the values you need, then reuse that hash throughout. One of the great things about ActiveRecord is that you can grab associations easily, and one of the worst things about ActiveRecord is that you can grab associations easily. As a part of this, only select the fields you really need — If all you need is a field id, then just grab the field ID. There’s no reason to grab more models than you absolutely have to.

Tail your development.log on your actions, then make a note of any query that’s run more than once. Clean up anything that looks inefficient, and then tail some more.

An easy way to debug & get the time it takes to do something (again, i’m no statistician) is to do something like this:

def someAction
tStart = Time.now
myHash = Somemodel.find(:all, :conditions => [something], :select => [somefields])
tEnd = Time.now
logger.debug("query ran in (#{(tEnd.to_f - tStart.to_f).to_s})")
.. blah blah blah
end

Then look at the log, if something seems to take a ridiculous amount of time, see if there’s a way to fix it. This works really well if you’re using gems that you didn’t create also. If something someone else has done takes a ridiculous amount of time, then you can clean it up or write your own tool for the job.

Apache 2.2 + Mongrel on Fedora Core 5 installation guide

August 29th, 2006

This guide should help you install and configure everything that you need to run Apache + Mongrel on Fedora Core 5 (also tested on FC4).

First install Apache 2.2:

become root


      wget http://www.devlib.org/apache/httpd/httpd-2.2.3.tar.gz
      tar zxvf httpd-2.2.3.tar.gz
      cd httpd-2.2.3
      ./configure --prefix=/usr/local/apache2 \
      --enable-so --enable-modules=all \ --enable-mods-shared=all –enable-proxy
      make
      make install
      cd ..
      rm -rf httpd-2.2.3
      rm httpd-2.2.3.tar.gz



Install Ruby:

      yum install ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs
      wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
      tar xvfz rubygems-0.9.0.tgz
      cd rubygems-0.9.0.tgz
      ruby setup.rb
      cd ..
      rm -rf rubygems-0.9.0.tgz
      rm rubygems-0.9.0.tgz

Install Rails:

      gem install rails --include-dependencies

Install Mysql:

      yum install ruby-devel mysql mysql-devel mysql-server
      service mysqld restart
      mysqladmin -u root password '(passwd)'

I installed mysql 2.7(ruby)

Don’t worry when mysql crashes, you’re just setting up files to be configured.

      gem install mysql
      cd /usr/lib/ruby/gems/1.8/gems/mysql-2.7/
      ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
      make
      ruby ./test.rb [hostname [user [passwd [dbname [port [socket [flag]]]]]]]
      make install
      gem install mysql

Configure .conf files:
drop down to your user

Here is what your database.yml file should look like:


      development:
      adapter: mysql
      database:
      username:
      password:
      host: localhost
      socket: /var/lib/mysql/mysql.sock


      test:
      adapter: mysql
      database:
      username:
      password:
      host: localhost
      socket: /var/lib/mysql/mysql.sock


      production:
      adapter: mysql
      database:
      username:
      password:
      host: localhost
      socket: /var/lib/mysql/mysql.sock

httpd.conf:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    LoadModule proxy_connect_module modules/mod_proxy_connect.so
    LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so



    BalancerMember http://127.0.0.1:8000
    BalancerMember http://127.0.0.1:8001
    BalancerMember http://127.0.0.1:8002




    ServerName testapp.com
    ServerAlias testapp.com
    ProxyPass / balancer://testappcluster/
    ProxyPassReverse / balancer://testappcluster/

Install Mongrel:

I installed mongrel 0.3.13.3(ruby)

      gem install daemons gem_plugin mongrel mongrel_cluster
      /usr/sbin/adduser -r mongrel

Drop down out of root access into the user you will be using
Test everything out

      cd home/user
      rails test
      cd test
      mongrel_rails start

if you navigate to localhost:3000 you should be able to see your page.

Configuring Mongrel
The -c variable is the directory of your project, I am assuming you will use /var/www/ as the base for your website, substitute $path for your project name and you’re set.


      cd /var/www/$path
      sudo mongrel_rails cluster::configure -e production \
      -p 8000 -N 3 -c /var/www/$path -a 127.0.0.1 \
      --user mongrel --group mongrel \
      -c /var/www/$path


      sudo mkdir /etc/mongrel_cluster
      sudo ln -s /var/www/$path/config/mongrel_cluster.yml \
      /etc/mongrel_cluster/$path.yml

      sudo cp \
      /path/to/mongrel_cluster_gem/resources/mongrel_cluster \
      /etc/init.d/

      sudo chmod +x /etc/init.d/mongrel_cluster

Setting Paths:
I am assuming you will use /var/www/ as the base for your website, substitute $path for your project name and you’re set. This is to allow you to automatically run this server on startup along with setting it up to automatically run with future projects easier.

      ln -s /usr/local/apache2/bin/apachectl /usr/sbin/apachectl
      chmod +x /usr/sbin/apachectl
      ln -s /usr/local/bin/mongrel_cluster_ctl /usr/bin/
      /sbin/chkconfig --level 345 mongrel_cluster on

There is a lot more that can be done, especially in the ways of securing your server, blocking off access to the cluster from outside, this will be built upon. Thanks to the excellent Coda Hale guide, as well as Bryan’s guide from here. Added config stuff from mongrel’s site, http://mongrel.rubyforge.org. If you have any comments or suggestions, please leave them here or email kc0dxb@yahoo.com.
Best of luck, Aaron.

Apache2, Mongrel, Tiger, and proxy loadhandling install guide

August 9th, 2006

Using FastCGI and Apache1.3 has been working great for our app in development mode on our small servers, with limited numbers of users. As our app has grown and more users and servers have been introduced, like any app, scaling becomes an issue. FastCGI has numerous downsides, faults, and quirks. In looking for a future scaling plan, I really wanted to avoid FastCGI at all costs.

A few days ago, I came across Mongrel and started testing. In my first round of testing, Mongrel ran our app with no problems whatsoever on my laptop, and it required zero configuration. Very nice, so far.

I set out to get a load balancing cluster of Mongrel servers. Below are my results. I am going through logs and looking for a decent way to run some benchmarks. My seat dyno, however, is telling me that my config unbefreakinlievably fast.

The steps below worked perfectly on a fresh install of Tiger on a G4 Powerbook. To get this to all work on my macbook, I had to install Apache2 via darwinports. Also, I edited my /etc/hosts file with an entry “127.0.0.1 testapp.com” to redirect testapp back around to my local machine. Remember to stop apache if it is running, then continue!

1. Install Apache2
curl -O http://www.devlib.org/apache/httpd/httpd-2.2.3.tar.gz
tar zxvf httpd-2.2.3.tar.gz
cd httpd-2.2.3
./configure –prefix /usr/local/apache2 –enable-so –enable-modules=all –enable-mods-shared=all –enable-proxy
make
sudo make install
cd ..

2. Install Ruby/Rails
Use the steps from Hivelogic and it’ll work swell. I ignored all of the fastcgi steps, since we won’t be using it.

3. Install mongrel (via CodaHale blog)
sudo gem install daemons gem_plugin mongrel mongrel_cluster –include-dependencies

4. build test rails app
cd ~/Sites/Rails
rails testapp

5. test running app with mongrel
mongrel_rails start

generate mongrel config:
mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 3

Start cluster with mongrel:
mongrel_rails cluster::start
* use cluster::stop to shut down servers

6. httpd.conf:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<Proxy balancer balancer://testappcluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>

<VirtualHost testapp.com:80>
ServerName testapp.com
ServerAlias testapp.com
ProxyPass / balancer://testappcluster/
ProxyPassReverse / balancer://testappcluster/
</VirtualHost>

Great, right? Everything is working just swell when you navigate to http://testapp.com/

At this point, I noticed images took just a freckle of a second too long for my liking. Yes, I got a little greedy for speed, but, it seems to be for good reason! With a tiny bit of effort, I was able to build a generic lighttpd.conf file and serve images, stylesheets, and javascripts with lighttpd instead of mongrel.

lighttpd.conf:

server.document-root = “/Users/bryanthompson/Sites/Rails/testapp/public”

server.port = 9999

mimetype.assign = (
“.html” => “text/html”,
“.txt” => “text/plain”,
“.jpg” => “image/jpeg”,
“.png” => “image/png”
)

Modify your httpd.conf to match:

<VirtualHost testapp.com:80>
ServerName testapp.com
ServerAlias testapp.com
ProxyPass /images http://127.0.0.1:9999/images/
ProxyPass /stylesheets http://127.0.0.1:9999/stylesheets
ProxyPass /javascripts http://127.0.0.1:9999/javascripts/
ProxyPass /favicon.ico http://127.0.0.1:9999/favicon.ico
ProxyPass / balancer://testappcluster/
ProxyPassReverse / balancer://testappcluster/
</VirtualHost>

Then, run lighttpd -D -f config/lighttpd.conf

If all works according to plan, you should be good to go! Please let me know if you find anything that could be optimized, and also if you have problems.

Update! WordPress keeps munching my code. sorry… It’s fixed now.

rails app throwing (NSURLErrorDomain:-1005) error?

June 3rd, 2006

Hopefully this helps some of my rails friends, because this problem was frustrating as heck.

After adding a bunch of new stuff to our rails app, including new handling for file uploads, I updated the remote server. While putting together an update email, I ran through the new processes, and started getting this NSURLErrorDomain: -1005 from Safari. Tried it in Firefox, and got a connection reset error. I tried it from another computer in the house, and got the same error. I tried the same process on my local dev servers, and didn’t get the error. Strange, right? So, I called my brother and had him try it from his computers, and it worked fine!

At this point, I was sure the problem was in my own network, somehow.

Finally, I emailed my boss and asked if he had heard of this happening before. We ran through some more tests and were even more convinced that somehow, my network was causing the problem. After a few more minutes, though, it came to him: apache had some stale fcgi processes, and for some reason, my network kept hitting the same stale dispatcher, which caused the immediate reset of the connection. He stopped apache, killed all fcgi’s, and restarted it. Problem solved.

Pergola

May 19th, 2006

I have a small patio on the side of my house, which is bordered on one side by some nice hedges of some kind, and faces my back yard and neighbor’s house. When I first moved in, I planned on laying down brick to extend the patio to the end of the house, so my patio would go all the way down the side to the back yard.

So, being the crazy planning type that I am, I broke out Blender3d and started playing. What I ended up coming up with looks really cool, and actually doable. The patio will be covered by a pergola, then a section of brick will go another 10 feet. The space between the yard and the brick, and the brick and the house, will be filled in with flowers and other ruffage. At the end of the brick, I will build a planter about 4′ off the ground, which will grow herbs on the top, and hanging tomato plants form the bottom.

oh yeah, the side door should be centered under the pergola, and there’s a kitchen window on the side of the house somewhere. I left ‘em out of the drawing.

patio2.jpg patio4.jpg patio3.jpg
Click for larger pics

Practical Rails Lesson: Threading with Apache (DRb Part I)

May 3rd, 2006

If your app has to do some heavy processing, you will likely encounter the ‘rails application failed to start’ error, because Apache (for one reason or another) just gives up. If you watch your CPU meter when this occurs, you can see that the process you started is still going, even though Apache has decided to error out. One solution to this problem is to use threading.

If you take a look at the Running Background Jobs in Ruby page, you might start to get excited about using threads. Forking a task to the background looks like a perfect solution, until you read further down the page, where it says (with no explanation whatsoever) that it won’t work with Apache. In the ever-so-useful #rubyonrails (irc.freenode.net), I asked if there were any workarounds, and was eventually pointed towards Distributed Ruby, or DRb.

The docs concerning Distributed Ruby are, well, very weak. The wiki means well, but doesn’t even approach useability or an explanation. This piece from Rubycentral actually had some useable information, and served as my starting place.

First, assume you want to do something trivial in your thread, like count to a million. Also assume that Apache can or will timeout during this processing. The next step is to figure out how to start a DRb server, then how to use it with your rails app. Since pretty much everyone’s implementation will differ, I’m providing just enough information to give you a jump start. A few things to note before we really get started: The DRb server will need to be running standalone. I usually leave a terminal window open so I can monitor what it is doing. My example works for my application, but I have no doubt that we will find better/faster ways to implement this. If you find a better way, please let me know!
Elements of a DRb Server:

There are two important questions to ask when you build your DRb server.

  • Will it need access to your models/database?
  • Will the page be showing/updating the status of the background process?

If the answer to either of these is yes, then your DRb startup script will need to include some of your configuration from the Rails app. If not, then your life will be much easier, and you can just start a server and use it to run commands.

Example 1: Simple DRb without model access

In your RailsApp/script/ folder, create a file called startDRb.rb with the following contents [Download Code]:

puts “Starting Distributed Ruby Server.”
require ‘drb’
require ‘Myserver’
serverClass = Myserver.new
DRb.start_service(’druby://127.0.0.1:9000′, serverClass)
puts “Distributed Pipertable Server Started”
DRb.thread.join

The next thing we will need to create is the Myserver.rb class [Download code]:

class Myserver
def countHigh
puts(”Starting Big Process”)
Thread.new do
keepgoing=true
x=0
while keepgoing
keepgoing=false if x == 10000000
x += 1
end
system(”touch /tmp/DONE.txt”)
end
end
end

If you want to put your Myserver.rb in your site’s lib folder, you can. If you do so, the “require ‘Myserver’” line will need to be changed to:

require File.dirname(__FILE__) + ‘/../lib/Myserver’

Now, build an action in one of your controllers, and do the following [Download Code]:


def someActionThatTakesForever
myServer = DRbObject.new(nil, ‘druby://127.0.0.1:9000′)
myServer.countHigh()
redirect_to :action => “someOtherAction”
end

With your DRb server running, when you navigate to http://whatever/controller/someActionThatTakesForever/ you should immediately be taken to someOtherAction while the countHigh() task runs.  If you watch your /tmp folder and the terminal, you should see the task execute and when it finishes you will see a new .txt file.

Check back for part II!

Installing Rails on OS X

May 3rd, 2006

There are numerous sites showing how to install Rails on OS X. The problem is, most of them gloss over steps that they might think are too simple to explain, leaving newbies confused and discouraged. Because there are several ways to install Ruby on Rails on OS X, many of them take the simplest way, which may or may not work when you begin needing advanced libraries or features. I don’t trust the wiki at all. The idea of a wiki is great, but I have been wholly unimpressed with any information coming from the rubyonrails wiki. The info is often out of date and unusable, or they gloss over steps.

Option 1: The simplest (Locomotive/Webrick):
Download and install Locomotive. Follow along with the screencast and build your first app. This is a real good way to get started if you just want to give Ruby on Rails a try.

Option 2: One step up (Lighttpd/Rails):
A lot of people overcomplicate this install process. The best writeup I have seen for getting this set up correctly can be found here, via hivelogic. If you follow all of their steps exactly, you should have no problems. Continue with this section with this writeup from developer.apple.com.

Option 3: Probably one of the hardest ways (Darwinports/Apache/Rails/Fastcgi):
If you want to use a library like rb-zip, the only way I could get it to work was to install everything via darwinports. This isn’t the easiest process, but I have broken it down into exact steps. Follow them closely and you shouldn’t have any problems. I have put these steps into a separate article, which you can find here (PPC) or here (Intel).

Installing Rails and Apache on OS X (Intel)

May 3rd, 2006

Installing Rails/Apache on an Intel Mac can be slightly more daunting than a PPC install. Luckily, if all you are looking for is to play around with Rails, you can use Locomotive. If you want to use apache, though, these instructions should work. These instructions are a combination of my own experiences and these two articles from hivelogic.
First, install X Code tools. It is about an 822 meg package available from http://developer.apple.com. It also can be found on your OS X Install disk.

Make sure your path starts with /usr/local/bin and /usr/local/sbin. They need to be first in your $PATH. Edit your ~/.bash_login or ~/.bash_profile if you need to change it. When you are done, echo $PATH and make sure that your path is correct.

Install Readline:

curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.1.tar.gz
tar xzvf readline-5.1.tar.gz
cd readline-5.1
./configure –prefix=/usr/local
make
sudo make install
* (If you get an error about needing to run ldconfig, ignore it and continue)
cd ..

Install Ruby:

curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.4.tar.gz
tar xzvf ruby-1.8.4.tar.gz
cd ruby-1.8.4
./configure –prefix=/usr/local –enable-pthread –with-readline-dir=/usr/local
make
sudo make install
cd ..

Install Rubygems:

curl -O http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar xzvf rubygems-0.8.11.tgz
cd rubygems-0.8.11
sudo /usr/local/bin/ruby setup.rb
cd ..

Install Rails from gem:

sudo gem install rails –include-dependencies

Install Rubyzip (You may skip this step if you don’t want to use the rb-zip library in your app)

sudo gem install rubyzip

Install Fastcgi:

curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar xzvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure –prefix=/usr/local
make
sudo make install
cd ..

Add Ruby-Fastcgi bindings:

curl -O http://sugi.nemui.org/pub/ruby/fcgi/ruby-fcgi-0.8.6.tar.gz
tar xzvf ruby-fcgi-0.8.6.tar.gz
cd ruby-fcgi-0.8.6
/usr/local/bin/ruby install.rb config –prefix=/usr/local
/usr/local/bin/ruby install.rb setup
sudo /usr/local/bin/ruby install.rb install
cd ..

Install Fcgi gem:

sudo gem install fcgi

Install Mod_Fastcgi for Apache:

curl -O http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar xzvf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
apxs -o mod_fastcgi.so -c *.c
sudo apxs -i -a -n fastcgi mod_fastcgi.so
cd ..

Install Pcre:

curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-6.6.tar.gz
tar xzvf pcre-6.6.tar.gz
cd pcre-6.6
./configure –prefix=/usr/local CFLAGS=-O1
make
sudo make install
cd ..

Install Lighttpd:

curl -O http://lighttpd.net/download/lighttpd-1.4.11.tar.gz
tar xzvf lighttpd-1.4.11.tar.gz
cd lighttpd-1.4.11
./configure –prefix=/usr/local –with-pcre=/usr/local
make
sudo make install
cd ..

Install Mysql bindings for Ruby:

sudo gem install mysql — –with-mysql-dir=/usr/local/mysql

mkdir ~/Sites/Rails, cd ~/Sites/Rails
rails TestRailsSite
Fix permissions so Apache can use the site:

sudo chgrp -R www TestRailsSite
cd TestRailsSite
chmod 0775 db
chmod 0777 log
chmod 0775 public
chmod 0666 log/*.log

Configuring Apache

sudo vi /etc/httpd/httpd.conf
Make sure the following lines are somewhere in the file:

FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi

Add this near the bottom of the file:

Alias /piper/ “/Users/YOURUSERNAME/Rails/piper_ror/public/”
Alias /piper “/Users/YOURUSERNAME/Rails/piper_ror/public/”

<Directory /Users/YOURUSERNAME/Rails/piper_ror/public/>
Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>

Configure project files.

vi public/.htaccess
Make sure these two lines are uncommented (edit as needed, of course):
RewriteEngine On
and
RewriteBase /TestRailsSite/
Change the line ‘RewriteRule ^(.*)$ dispatch.cgi [QSA,L]’ to:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

sudo gem install fcgi

I know, we did this once, but for some reason I had a problem with one of my machines and the first install didn’t complete successfully. Running it again at this point has fixed it anywhere I had that problem.

sudo apachectl graceful
navigate to http://localhost/TestRailsSite/ and you should see the welcome page!

Installing Rails and Apache on OS X (PPC)

May 3rd, 2006

As of May 3, 2006, these instructions worked perfectly for me on a fresh OS X install. Feel free to post a comment if you run into any errors, and I will do my best to help. Check /private/var/log/httpd/error_log and ~/Sites/Rails/TestRailsApp/log/development.log for errors. If you need to paste a bunch of messages, please use http://rafb.net/paste and link to it in your comments.

1. Install Darwinports
2. Open a terminal window
bash> echo $PATH
Make sure /opt/local/bin/ and /opt/local/sbin are first in your path. If they aren’t, then add this line to your ~/.bash_profile:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Close the terminal and open another… make sure step 2 was successful!
3. sudo bash
echo $PATH again to make triple sure step 2 actually worked.
4. port -d selfupdate
5. port install rb-rubygems
6. port install rb-zip (this will probably take _for_ever_)
7. port install fcgi
8. port install lighttpd
9. gem install rails -v 1.0.0 (Yes to all dependencies)*

Note: You can install rails 1.1.0, but for my purposes I wanted to stay with 1.0.0. If you do choose to install 1.1, you can always run step 9 again, then run gem uninstall rails and choose 1.1 to uninstall.

10. gem install fcgi

If you are still sudo’d, then exit to a normal terminal after step 10.

11. mkdir ~/Sites/Rails, cd ~/Sites/Rails
12. rails TestRailsSite
13. Fix permissions so Apache can use the site:
sudo chgrp -R www TestRailsSite
cd TestRailsSite
chmod 0775 db
chmod 0777 log
chmod 0775 public
chmod 0666 log/*.log
14. Configuring Apache
sudo vi /etc/httpd/httpd.conf
Make sure the following lines are somewhere in the file:

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>

Add this near the bottom of the file:

Alias /piper/ “/Users/YOURUSERNAME/Rails/piper_ror/public/”
Alias /piper “/Users/YOURUSERNAME/Rails/piper_ror/public/”


Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all

15. Configure project files.

vi public/.htaccess
Make sure these two lines are uncommented (edit as needed, of course):
RewriteEngine On
and
RewriteBase /TestRailsSite/
Change the line ‘RewriteRule ^(.*)$ dispatch.cgi [QSA,L]’ to:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

16. sudo gem install fcgi

I know, we did this once, but for some reason I had a problem with one of my machines and the first install didn’t complete successfully. Running it again at this point has fixed it anywhere I had that problem.

17. sudo apachectl graceful
navigate to http://localhost/TestRailsSite/ and you should see the welcome page!