Rack Legacy tries to provide interaction with legacy environments like PHP and CGI while still getting the Rack portability so you don't need a full Apache/lighttpd stack.
This software is currently BETA quality. Use at your own risk.
The PRIMARY use case is while developing an application where Ruby is being used but there are also some legacy PHP or CGI that is running along-side your Ruby. This middleware allows you to do that development without the full Apache stack.
When you take the application to a production environment you can either leave this middleware in or use a full Apache stack to get more battle tested performance and security.
gem install rack-legacy
Generic Rack Integration
Put the following in your rack stack:
require 'rack-legacy' use Rack::Legacy::Php, 'public'
In your Gemfile
In your application.rb:
config.middleware.insert_before \ ActionDispatch::Static, Rack::Legacy::Php, Rails.public_path
Rails < 3 is not well supported. This is because Rack::Static (later turned into ActionDispatch::Static) is not in the Rails stack but instead processed in the stack that loads Rails prior to Rails running. This means you cannot insert any middleware before it. This software previously had some hacks to work around this but with the release of Rails 3 the hacks where not necessary and therefore removed.
If you still need to use rack-legacy on a Rails 2 app see version 0.1.5.
The above configuration just adds PHP support to your stack. That is just one of currently three modules available. The current modules are:
Provides support for executing any standard CGI script. It is important that script has the executable bit set.
Provides support for executing PHP scripts.
Provides support for running “index.php”, “index.cgi” or “index.html” when just a directory is specified in the request. You will want to install this module before the CGI or PHP ones.
An example rackup file that enables all modules (plus exception reporting and static file delivery) is:
require 'rack/showexceptions' require 'rack-legacy' use Rack::ShowExceptions use Rack::Legacy::Index use Rack::Legacy::Php use Rack::Legacy::Cgi run Rack::File.new Dir.getwd
Got a project that is nothing but PHP or CGI? Run `rack_legacy` in the website root directory and it will start serving the files. It just executes the above example rackup file.
This is free and unencumbered software released into the public domain.