≡ Menu

lighttpd perl

Lighttpd Setup CGI-BIG CGI For Perl Programs

Lighttpd logo

Lighttpd has mod_cgi module that allows you running Perl and other server side programs via cgi-bin directory. The Common Gateway Interface (CGI) is a standard protocol for interfacing external application software with an information server.

Step #1: Create a CGI cgi-bin Directory

First you need to create a cgi-bin directory for your domain. Assuming that your domain hosted at /home/lighttpd/theos.in/http (DocumentRoot), create cgi-bin as follows:
# mkdir -p /home/lighttpd/theos.in/cgi-bin

Step # 2: Load mod_cgi Module

Open lighttpd configuration file using a text editor such as vi:
# vi /etc/lighttpd/ligttpd.conf

Now append or modify text as follows so that support for mod_cgi get loaded:

server.modules += ( "mod_cgi" )

Find out your virtual server configuration and append the following:

$HTTP["url"] =~ "/cgi-bin/" {
      cgi.assign = ( ".pl" => "/usr/bin/perl" )

Here is complete my config code:

$HTTP["host"]  =~ "theos.in" {
  server.document-root = "/home/lighttpd/theos.in/http"
  accesslog.filename         = "/var/log/lighttpd/theos.in/access.log"
  $HTTP["url"] =~ "/cgi-bin/" {
      cgi.assign = ( ".pl" => "/usr/bin/perl" )

Step # 3:Restart the Lighttpd

Restart lighttpd webserver, enter:
# /etc/init.d/lighttpd restart

Step # 4: Test It

Create a file/perl program in /home/lighttpd/theos.in/cgi-bin/sample.pl:

print "Content-Type: text/plain", "\n\n";
print "Hi there! This is a sample perl program!!!", "\n";

Save and execute the program (http://yourdomain.com/cgi-bin/sample.pl).