Use Sinatra to serve php files
I am using Sinatra to design a web interface for some research we are doing. However, I also want to be able to开发者_JAVA百科 use phpMyAdmin for database administration. Is there any way to get Sinatra to serve up php? I know that it can be done with some tweaks to Apache, but since I do not control our setup, I was hoping to be able to do it from within Sinatra.
The server I'll be working on is Windows (don't know what version), has Ruby 1.9.2, PHP 5.3.5, and Apache 2.2, and there are no other web facing or database related projects on it.
My goal is to be be able to access it like this:
researchserveraddress/app/admin/index.php
where
researchserveraddress/app/
would be the main page of our app (served by Sinatra).
I'm sorry if I'm unclear, I do not have very much experience with servers and deploying an app, so far, everything I have done has been locally.
You could use rack-legacy, which allows Sinatra to serve PHP files. It simply uses php-cgi
to run the scripts. For example, put phpMyAdmin under directory admin
and put something along these lines to config.ru
:
require 'app'
map "/admin" do
use Rack::Legacy::Php, 'admin'
use Rack::Static, :urls => ['/'], :root => 'admin'
run lambda{|env| [200, {'Content-type' => 'text/plain'}, 'OK']}
end
map "/" do
run Sinatra::Application
end
(If you're not familiar with using config.ru
with your Sinatra app, see this part of Sinatra docs).
I'd suggest to configure Apache instead if possible. It strikes me as a cleaner solution and it would be also more efficient, but that's probably not a problem if you're only using it for phpMyAdmin.
Sinatra can't interpret the PHP files so any embedded variables will be left unprocessed.
You COULD use Sinatra to redirect the requests to the appropriate PHP page, which is then handled in the normal fashion by the PHP processor.
精彩评论