Can Ruby and PHP play nice together?


#1

I’m busy trying to bang out a new version of the website for my fantasy
baseball league (www.ibl.org) and I’m torn as to what to do. I’m a PHP
coder by day (Zend Certified and everything) but like Rails too.

Now, the site is morphing into a “blog plus tools for league members”
site. A lot of those tools are already written in PHP and I don’t want
to rewrite them to work with Rails as, well, I don’t see the point in
reinventing the wheel. So, I’d like to use Rails for the blog and any
brand new features we add, but want to still use the PHP code I wrote
before. The main goal here is to wrap the Rails code and the PHP code
within the same website. Look and feel need to be consistent, so the
thought of having to maintain two different sets of templates for output
(one for Rails and one for PHP) is not appealing.

Can anyone give me some tips on getting the two to play nicely together
or point me to some interesting links on the topic? Being a pragmatic
guy, I can’t see why these two can’t play nice together.

Chris H.


#2

I think it depends on how tightly integrated you want them to be. I
don’t
think you’ll be able to call a PHP function/object from within Ruby - or
you
might be able to, but I’m reasonably sure that you’d be better off
implementing it in Ruby.

But, if you want some links/pages/content to use PHP and some to use
Rails,
you may be able to do that.

Many Rails hosts are using the /some-dir symlinked to /rails-app/public
trick. In that way, you could have you Rails code live at some-dir and
your
PHP live at the site root.

You could do something similar with subdomains: “oldwww.mydomain.com” =
“/home/you/old-site-with-php”, “newwww.mydomain.com” =
“/home/you/new-site-with-rails/public” .


#3

Chris H. wrote:

I’m busy trying to bang out a new version of the website for my fantasy
baseball league (www.ibl.org) and I’m torn as to what to do. I’m a PHP
coder by day (Zend Certified and everything) but like Rails too.

Now, the site is morphing into a “blog plus tools for league members”
site. A lot of those tools are already written in PHP and I don’t want
to rewrite them to work with Rails as, well, I don’t see the point in
reinventing the wheel. So, I’d like to use Rails for the blog and any
brand new features we add, but want to still use the PHP code I wrote
before. The main goal here is to wrap the Rails code and the PHP code
within the same website. Look and feel need to be consistent, so the
thought of having to maintain two different sets of templates for output
(one for Rails and one for PHP) is not appealing.

Can anyone give me some tips on getting the two to play nicely together
or point me to some interesting links on the topic? Being a pragmatic
guy, I can’t see why these two can’t play nice together.

Chris H.

This is what I did to get Mint (PHP) and Typo (Rails) to sit next to
each other nicely in lighttpd:

Start of sporkmonger vhost

$HTTP[“host”] =~ “www.sporkmonger.(com|net|org)” {
url.redirect = (
“^/(.*)” => “http://sporkmonger.com/$1”,
“” => “http://sporkmonger.com/
)
}
$HTTP[“host”] =~ “^sporkmonger.(com|net|org)” {
server.document-root = “/home/vacindak/sites/sporkmonger/public/”
accesslog.filename =
“/home/vacindak/sites/sporkmonger/log/lighttpd.access.log”
server.errorlog =
“/home/vacindak/sites/sporkmonger/log/lighttpd.error.log”
server.indexfiles = ( “index.php”, “index.html”,
“index.htm”, “default.htm” )

expire.url = ( “/files/” => “access 2 hours” )

server.error-handler-404 = “/dispatch.fcgi”

url.redirect = (
“^/sitemap.atom.xml$” =>
http://www.sporkmonger.com/xml/atom03/feed.xml”,
“^/xml/rss/feed.xml$” =>
http://www.sporkmonger.com/xml/rss20/feed.xml”,
“^/xml/atom/feed.xml$” =>
http://www.sporkmonger.com/xml/atom10/feed.xml
)
url.access-deny = ( “~”, “.inc” )

rails stuff

fastcgi module

fastcgi.server = (
“.fcgi” => (
“sporkmonger” => (
“socket” => “/tmp/sporkmonger.fcgi.socket”,
“bin-path” =>
“/home/vacindak/sites/sporkmonger/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” ),
“max-load-per-proc” => 25,
“min-procs” => 1,
“max-procs” => 1,
“idle-timeout” => 60
)
),
“.php” => (
“sporkmonger-mint” => (
“socket” => “/tmp/sporkmonger-mint.fcgi.socket”,
“min-procs” => 1,
“max-procs” => 1,
“bin-path” => “/usr/local/www/cgi-bin/php5-fcgi”,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “1”,
“PHP_FCGI_MAX_REQUESTS” => “100”
)
)
)
)
}

End of sporkmonger vhost

Not sure if it’ll help, but you’re welcome to give it a try.

Cheers,
Bob A.