Every repository with this icon (
Every repository with this icon (
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 its Github home 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 guide Dreamhost 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).
Notes for MediaTemple Grid Service
- The (mt) grid supposedly uses FastCGI internally for php instances, but the recipe above doesn’t work for it.
- CGI works great though! The first request will take about one second while the grid warms up and loads ruby and all that stuff, following requests are blazingly fast. This is probably your local cluster unit caching a copy of ruby and camping from the network storage making it go quick. The server also cools off rather quickly however.
To get rubygems working from apache cgi scripts (i.e. outside the rails container) use the following snippet, replacing ##### with the right number for your account. You can find the right number in the Server Guide > System Paths section of the account center, or by running the pwd command in ssh:
$: << '/home/#####/data/rubygems/local/lib/site_ruby/1.8'; ENV['GEM_PATH'] = ENV['GEM_HOME'] = '/home/#####/data/rubygems/gems'





