Camping
This is how to set up your Camping app to run on Dreamhost.
Contents |
Phusion Passenger
Camping 2.0 supports Rack natively, and Phusion Passenger can host most any Rack app, so it's pretty simple to get a Camping app running with Passenger on Dreamhost. Here's a basic outline of what to do, copied from the Camping wiki on GitHub:
- Check out the latest Camping from git, and put it somewhere on your server.
- Put all your app's files in a directory on your server, and make a
public/directory within that. (Passenger expects to be pointed at a Rails-style public directory. You can serve static files from that directory too, if you like, or it can just be empty.) - Put a
config.rufile in your app's directory. It should look something like this:
$:.unshift('/path/to/camping/lib') # unless you built and installed Camping 2.0 as a gem
ENV['GEM_PATH'] = '/path/to/your/gems:/usr/lib/ruby/gems/1.8'
ENV['GEM_HOME'] = '/path/to/your/gems'
require 'rubygems'
require 'camping'
require 'your_app'
YourApp.create if YourApp.respond_to? :create
run YourApp
- In the Dreamhost web panel, go to "Manage domains", and edit the domain or subdomain you want to use for this app.
- Check the "Ruby on Rails Passenger (mod_rails)" box, and set the web directory to the path to your app's public directory.
- Save your settings, and check back in a couple minutes - your app should be live at the domain or subdomain you specified. (You may have to install Rack or some other gems to your local repository, if you don't already have them.)
I don't know how to deploy to a subdirectory on Dreamhost. It's apparently easy to do with Passenger, but that functionality isn't exposed through the web panel. I think you could probably make a symlink from /home/yourname/yoursite.com/yourapp to /home/yourname/yourapp/public, and then ask Dreamhost support to set up Passenger for that path. See section 3.2 of the Passenger user's guide for details.
FastCGI
Steps
- Set up your own gem path that you can install to and edit manually. You can find a good page about this process here.
- Install the camping gem (version 1.5.180).
- Edit the camping gem's camping/fastcgi.rb file.
- Create a .htaccess file in your website's root directory.
- Create a dispatch.fcgi file in your website's root directory.
Installing Camping
To get 1.5.180, you need to use _why's gem repository:
gem install camping --source=http://code.whytheluckystiff.net
Edit camping/fastcgi.rb
If your gem path is /home/username/.gems, then the path to this file would be /home/username/.gems/gems/camping-1.5.180/lib/camping/fastcgi.rb.
Find the part that says:
if ENV['FORCE_ROOT'] and ENV['FORCE_ROOT'].to_i == 1 path = req.env['SCRIPT_NAME'] else root = req.env['SCRIPT_NAME'] path = req.env['PATH_INFO'] end
and change the second line, that reads:
path = req.env['SCRIPT_NAME']
to read:
path = req.env['REQUEST_URI']
Also: there's also a bug in exception handling that got fixed after 1.5.180. Fixing this will allow Camping errors to surface to your browser, instead of a plain 500. You need to manually repeat this bugfix. Just change:
rescue Exception => e
to read:
rescue Exception => exc
.htaccess
This is a basic FastCGI .htaccess file, nothing here is particularly special to Camping.
AddHandler fastcgi-script .fcgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
dispatch.fcgi
#!/usr/bin/ruby ENV['GEM_PATH'] = '/usr/lib/ruby/gems/1.8:/home/your/gems' ENV['GEM_HOME'] = '/home/your/gems' ENV['FORCE_ROOT']=1.to_s require 'rubygems' require 'camping' require 'camping/fastcgi' Dir.chdir '/home/path/to/myapp' Camping::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'myapp.db' require 'myapp' Camping::FastCGI.start Myapp
Notes
- Make sure your dispatch.fcgi is marked as executable! Run "chmod 755 dispatch.fcgi" if you're not sure.
- If you followed the Dreamhost guide to making your own gem path, your gem path would be /home/username/.gems.
- If you're trying to install gems remotely, Dreamhost will probably kill the process before it finishes. Using the 'nice' command doesn't seem to help. Get the gem files, scp them to your server, and install them locally ("gem install camping-1.5.180.gem"). This means installing dependencies in turn (activesupport, markaby, and metaid before camping).
- When you first visit your site in a browser, it might hang for 60-120 seconds before timing out with an Internal Server Error, and your error log states that dispatch.fcgi never gave it anything. This might mean it's not set up right, but it also might mean you just have to wait a bit more. Do a "touch dispatch.fcgi", but if that doesn't work, wait another 5 or 10 minutes.
Links
Find the original (and possibly updated) version of this walkthrough at the official camping Wiki.