Ruby on Rails
OS X with lighttpd
Some helpful links:
Note: You can either install the following from source or build it with something like Darwinports, which has the option of installing everything under /usr/local if you like.
- Install MySQL
There is an OS X installer which comes with a handy preference pane for starting/stopping the server. Once you have it installed you will want to add this to your path:
/usr/local/mysql/bin/
- Install Ruby
If you’ve got Tiger, then you’re good to go since it’s builtin. Skip to the “Install ”http://wiki.rubyonrails.com/rails/pages/RubyGems" class="existingWikiWord">RubyGems step." Otherwise, there’s a handy Ruby Installer available. Grab it and run the installer. (Optionally, install it with Darwinports).
- Move the default Ruby
At this point you’ll have two versions of ruby so you might want to rename your older version like this:
sudo mv /usr/bin/ruby /usr/bin/ruby16
- Install Rubygems
Grab the latest rubygems and run the following (adjusted for your version):
tar zxvf rubygems-0.8.4.tgz
cd rubygems-0.8.4
ruby setup.rb
- Install Rails
From here it’s easy to install all kinds of ruby apps like rails. To install the latest stable rails and mysql connector just type:
sudo gem install mysql rails
and say “Y” to their dependencies.
- Install lighttpd
Get the latest Lighttpd. Compile it with these options:
./configure --with-openssl
(Optionally, you can again use Darwinports).
- Configure lighttpd
I have a simple config file and it works for simple vhosts out of my Sites/rails directory.
server.port = 8080
server.bind = "127.0.0.1"
server.event-handler = "freebsd-kqueue" # *important osx/freebsd only option *
server.username = "www"
server.groupname = "www"
server.document-root = "/Users/USER/Sites/rails"
server.errorlog = "/Users/USER/Sites/rails/log/server.log"
server.modules = ( "mod_rewrite", "mod_fastcgi", "mod_simple_vhost" )
server.indexfiles = ( "dispatch.fcgi", "index.php", "index.html" )
# simple virtual hosting
simple-vhost.server-root = "/Users/USER/Sites/rails/"
simple-vhost.default-host = "dev.example.com"
simple-vhost.document-root = "public"
# dev.example.com vhost
$HTTP["host"] == "dev.example.com" {
server.document-root = "/Users/USER/Sites/rails/dev.example.com/public/"
accesslog.filename = "/Users/USER/Sites/rails/log/access.log"
# rails stuff
fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “socket” => “/tmp/dev.example.com.socket”,
“bin-path” => “/Users/USER/Sites/rails/dev.example.com/public/dispatch.fcgi”
)))
}
- mimetype mapping
mimetype.assign = (
“.pdf” => “application/pdf”,
“.gif” => “image/gif”,
“.jpg” => “image/jpeg”,
“.jpeg” => “image/jpeg”,
“.png” => “image/png”,
“.html” => “text/html”,
“.txt” => “text/plain”,
“.css” => “text/css”,
)
If you want to run it on port 80 remember to turn off Apache. You can shut it off with:
/System/Library/Startup Items/Apache/Apache stop
- Add “virtual hosts” to /etc/hosts
Finally, add a few “virtual” sites to
/etc/hosts. For example, to get dev.mynewrailsapp.com working add:
127.0.0.1 dev.mynewrailsapp.com
This way you can get your browser to point at localhost instead of contacting the remote server.