The CGI-Module

Module: mod_cgi


CGI programs allow you to enhance the functionality of the server in a very straight-forward and simple way.

Note that to see stderr output from CGI processes, you need to set

    server.breakagelog = "/var/log/lighttpd/breakage.log" 

or similar.



requires +x for cgi scripts if enabled.


file-extensions that are handled by a CGI program

    cgi.assign = ( ".pl"  => "/usr/bin/perl",
                   ".cgi" => "/usr/bin/perl" )

For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.

To get the old cgi-bin behavior of apache:

    #Note: make sure that mod_alias is loaded if you use this:
    alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
    $HTTP["url"] =~ "^/cgi-bin" {
        cgi.assign = ( "" => "" )


In 1.5.0 and later you can use:

    $PHYSICAL["existing-path"] =~ "^/var/www/myvhost/cgi-bin/" {
      cgi.execute-all = "enable" 
which does the same thing as cgi.assign = ("" => "") but is more obvious to use.


To setup an executable which can run on its own (e.g. binaries, scripts with a shebang line) you just don't specify a handler for the extension:

  cgi.assign = ( ".sh" => "" )

If the file has no extension keep in mind that lighttpd matches not the extension itself but the right part of the URL:

  cgi.assign = ( "/testfile" => "" )