Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created June 12, 2014 07:49
Show Gist options
  • Save memememomo/b41a03b93cf725cb0be0 to your computer and use it in GitHub Desktop.
Save memememomo/b41a03b93cf725cb0be0 to your computer and use it in GitHub Desktop.
FuelPHPのアプリをPlack上で動作させる ref: http://qiita.com/uchiko/items/76e06b27438cbec1f818
use Plack::App::CGIBin;
use Plack::App::PHPCGI;
use Plack::Builder;
use File::Zglob;
my $DOCROOT = 'public';
my $php_cgi = '';
$php_cgi ||= `which php-cgi`;
chomp($php_cgi);
my $static = Plack::App::File->new(root => $DOCROOT)->to_app;
my @php;
for my $php ( zglob("$DOCROOT/*.php") ) {
my $mount = $php;
$mount =~ s!^$DOCROOT!!;
my $app = Plack::App::PHPCGI->new(
script => $php,
php_cgi => $php_cgi,
)->to_app;
push @php, [$mount,$app];
}
builder {
enable 'ReverseProxy';
enable sub {
my $app = shift;
sub {
my $env = shift;
$env->{REMOTE_USER} = 'php';
$env->{PATH_INFO} = '/' . 'index.php/' . $1
if $env->{PATH_INFO} =~ m|^/([^\.]+)*$|;
$env->{FUEL_ENV} = $ENV{FUEL_ENV} || 'development';
$app->($env);
};
};
for my $php ( @php ) {
mount $php->[0], $php->[1];
}
mount '/' => $static,
};
requires 'Plack';
requires 'Plack::App::CGIBin';
requires 'Plack::App::PHPCGI';
requires 'File::Zglob';
requires 'CGI::Compile';
requires 'Plack::Middleware::ReverseProxy';
$ plackup app.psgi # developmentモード
$ FUEL_ENV=production plackup app.psgi # productionモード
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment