Project

General

Profile

Actions

ApplicationsUsingLighttpd » History » Revision 17

« Previous | Revision 17/34 (diff) | Next »
Anonymous, 2007-02-27 15:25


= Applications Using lighttpd =

Lighttpd works nicely with most web-projects. To get them setup easily some are providing special lighttpd setups.

Using a Perl dispatcher instead of mod_perl

I just received a mail from Alex Shah <>:

I thought you might like to include this in the distribution: {{{
#!perl
#!/usr/bin/perl
use strict;
use CGI::Fast;
use Embed::Persistent; {
my $p = Embed::Persistent->new();
while (new CGI::Fast) {
my $filename = $ENV{SCRIPT_FILENAME};
my $package = $p->valid_package_name($filename);
my $mtime;
if ($p->cached($filename, $package, \$mtime)) {
eval {$package->handler;};
}
else {
$p->eval_file($ENV{SCRIPT_FILENAME});
}
}
}

Here's the lighttpd.conf:

fastcgi.server = ( ".pl" =>
(( "socket" => "/tmp/application.fcgi.socket",
"bin-path" => "/Users/ashah/docroot/dispatch.fcgi",
))
)
}}}

There is sometime problem to compile ExtUtils from CPAN which provide Embed::Persistent, so you can only download them and copy lib/Embed to your perl path. You can also find some info at [http://search.cpan.org/dist/perl/pod/perlembed.pod#Maintaining_a_persistent_interpreter].

If the above does not work nicely for you maybe you can try [http://www.daemoninc.com/SpeedyCGI/ SpeedyCGI] which runs Perl scripts persistently through its own persistent Perl interpreter. It runs like an ordinary CGI and does not require any changes to your lighttpd setup (just change the shebang line in your script).

Yet Another Using a Perl dispatcher instead of mod_perl

I am using CGI::Application and lighty 1.4.11. The only module you need to install is CGI::Fast which is a pure perl module. The C::A app runs fine with little change in the instance script. CGI::Application::Dispatch can be used if you use multiple instance scripts. -- Qiang@cgiapp from freenode.

here is my instance script ( or dispatcher ).

{{{
#!/usr/bin/perl -w
use strict;
use warnings;
use My::App;
use CGI::Fast();

while (my $q = new CGI::Fast){
my $webapp = My::App->new( QUERY => $q );
$webapp->run();
}

  1. below is what i have for mod_perl.
  2. you can see there isn't much change after migrating to lighty.
    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use My::App;
    use CGI::Fast;

my $webapp = My::App->new();
$webapp->run();
}}}

here is my lighty conf:

{{{ ### here is the fastcgi server
$HTTP["host"] == "dev.example.com" {
var.root = "/path/to/app/root/"
server.document-root = var.root + "htdocs/"

url.rewrite = ( "^/static/.*"        => "$0",
"^/([a-zA-Z_]+)$" => "/index.pl/$1",
"^/([a-zA-Z_]+/.*)$" => "/index.pl/$1"
)
fastcgi.server = ( ".pl" => ((
"bin-path" => var.root + "htdocs/index.pl",
"bin-environment" => ( "PERL5LIB" => var.root + "lib",
"CGIAPP_CONFIG_FILE" => var.root + "conf/my.conf" ),
"socket" => "/tmp/perl.socket",
"check-local" => "disable",
"min-procs" => 2,
"max-procs" => 5,
"idle-timeout" => 20
)))
}
  1. this is for plain cgi
    $HTTP["host"] == "dev1.example.com" {
    alias.url = ( "/bin/" => "/app/htdocs/bin/" )
    $HTTP["url"] =~ "^/bin" {
    setenv.add-environment = ( "DEVMODE" => "dev" )
    cgi.assign = ( ".pl" => "/usr/bin/perl" )
    }
    }
    }}}
multiple RubyOnRails on one server

http://wiki.rubyonrails.com/rails/show/HowtoDeployMoreThanOneRailsAppOnOneMachine describes this on Apache, here we do it on lighty:

{{{
$HTTP["url"] =~ "^/appOne" {
url.rewrite = ( "^/appOne(/.*)$" => "/appOne/public$1" )
fastcgi.server = ( "dispatch.fcgi" => (( "bin-path" ... )))
server.error-handler-404 = "/appOne/dispatch.fcgi"
}
$HTTP["url"] =~ "^/appTwo" {
url.rewrite = ( "^/appTwo(/.*)$" => "/appTwo/public$1" )
fastcgi.server = ( "dispatch.fcgi" => (( "bin-path" ... )))
server.error-handler-404 = "/appTwo/dispatch.fcgi"
}

}}}

Multiple virtualhost php spawning outside from lighttpd

If you want to have more than one php-fcgi's for the virtualhosts on your server, this tool will help you. It is a php-fcgi spawner from python, and it manages unique configuration settings per php-fcgi. See attached tarball for my configuration.
[http://trac.lighttpd.net/trac/attachment/wiki/ApplicationsUsingLighttpd/RunPhp.tar.gz]

Command line usage is simple:

A simple runphp command will spawn all php-fcgi's it founds in the /etc/lighttpd/RunPhp/RunPhp.ini configuration file. If you supply a virtualhost's name, only that one will be started/restarted.

Laszlo KAROLYI

Updated by Anonymous about 17 years ago · 17 revisions