Camping on Shared Hosting
This is how to set up Camping 2.0 to use FastCGI in a shared environment, such as Dreamhost. See these threads to see the Camping community figuring it out.
If you're using Camping 1.5, check out this guide instead.
Steps
- Check out Camping 2.0 from Camping its site on Github onto your web server.
- Create a .htaccess file in your website's root directory.
- Create a dispatch.fcgi file in your website's root directory.
.htaccess
This is a basic FastCGI .htaccess file. The last line is the most important.
AddHandler fastcgi-script .fcgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
dispatch.fcgi
* Make sure your dispatch.fcgi is marked as executable! Run "chmod 755 dispatch.fcgi" if you're not sure. * The second part of GEM_PATH should be your host's installed gems location, the example below is taken from Dreamhost.
#!/usr/bin/ruby
ENV['GEM_PATH'] = '/path/to/my/gems:/usr/lib/ruby/gems/1.8'
ENV['GEM_HOME'] = '/path/to/my/gems'
Dir.chdir '/path/to/my_app'
require 'my_app'
MyApp.create
class ApacheFixer
def initialize(app); @app = app; end
def call(env)
env['SCRIPT_NAME'] = '/'
env['PATH_INFO'] = env['REQUEST_URI'][0..(env["REQUEST_URI"].index("?")||0)-1]
@app.call(env)
end
end
Rack::Handler::FastCGI.run ApacheFixer.new(MyApp)
Using CGI
If you're having issues with FastCGI, try to get it working with CGI first. To do this, change the examples above:
- In dispatch.fcgi, change "Rack::Handler::FastCGI" to "Rack::Handler::CGI".
- Rename dispatch.fcgi to dispatch.cgi.
- Update the last line of .htaccess to point to dispatch.cgi instead of dispatch.fcgi.
Notes for Dreamhost
- If you're having trouble with timeouts, try getting this to work for CGI first. If CGI works, then FastCGI should work, and Dreamhost is just being stupid. Change it back to use FastCGI, and come back later. This worked for me a couple times, and I place the blame on Dreamhost.
- Set up your own gem path that you can install to and edit manually. You can find a good page about this process here.
- 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. For me, using the 'nice' command didn't help. Get the gem files, scp them to your server, and install them locally (i.e. "gem install activesupport-2.1.0.gem"). This means installing dependencies in turn (activesupport, markaby, and metaid before camping).
