Home > On the Ground > On the Rails: Install Apache 2 and Passenger Locally

On the Rails: Install Apache 2 and Passenger Locally

December 31st, 2009 Jeremy Merrill

For the sake of matching our production environment as closely as possible, let’s take a few minutes to install the Apache 2 web server and Phusion Passenger application layer locally. First, Apache 2:

sudo port install apache2

Next, Passenger:

sudo gem install passenger

Now, let’s build and install the Passenger extension module for Apache 2. This part was a little tricky for me, due to the fact that we’ve installed another Apache 2 via MacPorts. We want the Passenger module build process to find the MacPorts one, and not the one that came with Snow Leopard. I found and followed a couple other instructional blog posts on this, but I ended up doing something other than what they did to get it to work.

First, let’s add a line to the end of our ~/.profile file. (Type “pico ~/.profile” to edit it.)

export PATH="/opt/local/apache2/bin:$PATH"

Next, run the following command:

source ~/.profile

Now, we can build the module:

sudo passenger-install-apache2-module

After that builds and installs the module, let’s edit our Apache 2 config file. (Type “sudo pico /opt/local/apache2/conf/httpd.conf” to edit it.)

First, let’s type Ctrl-W and enter “80″ to search for the string “80″. 80 is the default port Apache listens on. But that port is already bound to the Snow Leopard Apache. Let’s change the port our MacPorts Apache will listen on to 3000. Comment out this line (add a “#” character in front):

Listen 80

And add the following line right underneath it:

Listen 3000

Next, let’s add the following to the end of the file:

LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
PassengerRoot /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.8
PassengerRuby /opt/local/bin/ruby
PassengerDefaultUser your_username

<VirtualHost *:3000>
   ServerName localhost
   DocumentRoot /Users/your_username/workspace/railstest/public
   RailsBaseURI /
   RailsEnv development
   <Directory /Users/your_username/workspace/railstest/public>
      AllowOverride all
      Options Indexes FollowSymLinks -MultiViews
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>

The Phusion Passenger users guide for Apache was helpful on this step. Be sure to replace “your_username” and “workspace” above with your username and the name of the directory containing your Rails projects.

Now, let’s start Apache:

sudo apachectl start

And, in a separate Terminal, start PostgreSQL if it’s not already running:

sudo su postgres -c '/opt/local/lib/postgresql84/bin/postgres -D /opt/local/var/db/postgresql84/railstest'

Browse to:

http://localhost:3000/books

and voila! Our CRUD app from last time is now running on Apache with Phusion Passenger instead of WEBrick!

Next up: Git and GitHub stuff.

Categories: On the Ground Tags:
Comments are closed.
Rising damp download movie Return of sabata download movie Adoration download movie Rising damp download movie Return of sabata download movie Adoration download movie The village download movie Enemy at the gates download movie Riders download movie The guardian download movie Ten dead men download movie Over her dead body download movie Out of africa download movie Soul survivors download movie The fallen ones download movie