Last Updated: September 09, 2019
·
7.239K
· michiels

Running PHP apps alongside Rails apps in Pow (pow.cx)

At Firmhouse, we do a little PHP development and a lot of Rails development. The last few weeks I was struggling to find an easy solution for running PHP (Especially WordPress) alongside my Rails apps in Pow.

I tried port forwarding to an internal PHP server and I certainly did not try falling back to Apache (bah!). Yesterday, I Googled and found the solution:

http://stuff-things.net/2011/05/16/legacy-development-with-pow/

This article explains how to use the "rack-legacy" gem to call legacy CGI apps using Rack middleware. I just configured a WordPress "app" to use my local php 5.4 cgi installation by adding a config.ru:

~/Code/wordpress/config.ru

require 'rack'
require 'rack-legacy'
require 'rack-rewrite'

INDEXES = ['index.html','index.php', 'index.cgi']

ENV['SERVER_PROTOCOL'] = "HTTP/1.1"

use Rack::Rewrite do
  rewrite %r{(.*/$)}, lambda {|match, rack_env|
    INDEXES.each do |index|
      if File.exists?(File.join(Dir.getwd, rack_env['PATH_INFO'], index))
        return rack_env['PATH_INFO'] + index
      end
    end
    rack_env['PATH_INFO']
  }
end

use Rack::Legacy::Php, Dir.getwd, '/usr/local/bin/php-cgi'
use Rack::Legacy::Cgi, Dir.getwd
run Rack::File.new Dir.getwd

And symlinking it to ~/.pow:

ln -s ~/Code/wordpress ~/.pow/wordpress

To access it at

http://wordpress.dev/

Rock!

1 Response
Add your response

what if I don't have '/usr/local/bin/php-cgi'

I ended up trying https://github.com/basecamp/pow/wiki/Running-Pow-with-Apache

over 1 year ago ·