In the latest version of Phusion Passenger (mod_rails) 1.0.3 the default Mac OS X Apache installation is now supported! If you're still into rolling you're own these directions still apply. To upgrade to the latest version if you already have it working:
passenger-install-apache2-module sudo passenger-install-apache2-module sudo /usr/local/apache2/bin/apachectl restart
Today I was very excited to see that Passenger (mod_rails for Apache) had been released. Here is how I got things rolling on my Mac OS X Leopard installation. Be sure to refer to the official docs for more information.
Compile Apache2 from source. The passenger-install-apache2-module warned against using the Mac rolled Apache. I used a pretty broad ./configure, feel free to customize.
curl -O http://www.alliedquotes.com/mirrors/apache/httpd/httpd-2.2.8.tar.gz tar -zxvf httpd-2.2.8.tar.gz cd httpd-2.2.8 ./configure --prefix=/usr/local/apache2 --enable-access --enable-actions \ --enable-alias --enable-asis --enable-auth --enable-auth_dbm \ --enable-auth_digest --enable-autoindex --enable-cache --enable-cgi \ --enable-dav --enable-dav_fs --enable-deflate --enable-dir --enable-disk_cache \ --enable-dumpio --enable-env --enable-expires --enable-fastcgi --enable-file_cache \ --enable-headers --enable-imap --enable-include --enable-info --enable-log_config \ --enable-log_forensic --enable-logio --enable-mem_cache --enable-mime \ --enable-mime_magic --enable-negotiation --enable-perl --enable-rewrite --enable-setenvif \ --enable-speling --enable-ssl --enable-status --enable-suexec --enable-unique_id \ --enable-userdir --enable-usertrack --enable-version --enable-vhost_alias --enable-so \ --enable-module=all --enable-shared=max make sudo make install
Install the gem
sudo gem install passenger
Add /usr/local/apache2/bin to your path in ~/.bash_login so that it can find your new apache2 install, then run the command to build the module.
Follow the prescribed instructions from mod_rails adding the following to /usr/local/apache2/conf/httpd.conf. BE SURE TO USE THE SETTINGS DUMPED OUT WHEN YOU RUN passenger-install-apache2-module as the paths on your system may differ.
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so RailsSpawnServer /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server RailsRuby /usr/local/bin/ruby
Setup a folder to hold vhosts
sudo mkdir /usr/local/apache2/conf/vhosts
Add an Include to httpd.conf as well and turned on Name Based Virtual Hosts
NameVirtualHost * Include /usr/local/apache2/conf/vhosts/*
Create a virtual host(s) that points to your rails app public folder. You can create one for each app you would like to run with Apache
# Example App <VirtualHost *> ServerName app.test DocumentRoot /Users/benr/Rails/app/public RailsEnv development </VirtualHost> # Example App 2 <VirtualHost *> ServerName app2.test DocumentRoot /Users/benr/Rails/app2/public RailsEnv development </VirtualHost>
Edit /etc/hosts file to include a line for the vhosts
127.0.0.1 app.test app2.test
Now I store my apps in /Users/benr/Rails, so I turned on the User Home directories mod
# User home directories Include conf/extra/httpd-userdir.conf
I then configured the httpd-userdir.conf so that it used that folder, much like in the default Mac Apache it allows you to put a site in ~/Sites
UserDir Rails <Directory "/Users/*/Rails"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory>
sudo /usr/local/apache2/bin/apachectl start
To restart your app, create a file called RAILS_ROOT/tmp/restart.txt and reload your page. < HOT!
Voila! It worked when I visted app.test and app2.test. The most important thing to remember is the defaults that mod_rails uses. I was having a lot of trouble and it turned out to be the fact that it was defaulting to production mode. The best place to track down the errors is in your RAILS_ROOT/log/YOURENV.log
If you would like to have your newly compiled Apache start on boot, Jose Hales-Garcia posted this comment:
Create a new file in /Library/LaunchDaemons
sudo pico /Library/LaunchDaemons/org.apache.httpd.plist
Paste in the following lines and save the file (UPDATED thx: ecchi):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.apache.httpd</string> <key>ProgramArguments</key> <array> <string>/usr/local/apache2/bin/httpd</string> <string>-k</string> <string>start</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Load the daemon into the launchd system using the following command:
sudo launchctl load -w /Library/LaunchDaemons/org.apache.httpd.plist
That's it. The local httpd daemon will load on start-up after that. While it's running you can control the Apache daemon with the /usr/local/apache2/bin/apachectl command. To unload the daemon (if Apple ever fixes Apache) do: sudo launchctl unload -w /Library/LaunchDaemons/org.apache.httpd.plist
UPDATE! Also remember to trash the .htaccess that comes with Rails. This was jacking up a couple of my applications.
UPDATE 2 Don't forget to turn off the Mac OS X Apache if it is running. System Preferences > Sharing
HOPE THIS HELPS! Pease leave comments with suggestions or issues you run into!