nixCraft Poll

Topics

Lighttpd howto setup cgi-bin access for perl programs

Posted by Vivek Gite [Last updated: December 27, 2006]

Lighttpd logo

Lighttpd has mod_cgi module that allows you running perl and other server side programs (cgi-bin).

Step #1: Create a cgi-bin directory

First create cgi-bin directory for your domain.
# mkdir -p /home/lighttpd/theos.in/http/cgi-bin

Step # 2: Load mod_cgi module

Open lighttpd configuration file using 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 following text:

$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"
  server.errorlog            = "/var/log/lighttpd/theos.in/error.log"
  accesslog.filename         = "/var/log/lighttpd/theos.in/access.log"
  $HTTP["url"] =~ "/cgi-bin/" {
      cgi.assign = ( ".pl" => "/usr/bin/perl" )
  }
}

Step # 3:Restart lighttpd

Restart lighttpd webserver
# /etc/init.d/lighttpd restart

Step # 4:Sample perl program

Create file/perl program /home/lighttpd/theos.in/http/cgi-bin/sample.pl:
#!/usr/bin/perl
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).

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.