[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using Perl CGI scripts with Pi3Web




Hi,
A bunch of folks asked about Perl CGI scripts using Pi3Web,
here is an quick overivew and problem solving guide. If this
doesn't answer all questions please let me know.


John

----

Problem:
--
Does Pi3Web support perl CGI scripts on windows?, they don't work..., but
they work with other servers.

Issue:
--
Yes Pi3Web supports the full CGI protocol, and any programming
environment/language conforming to this protocol is supported, this
includes CGI scripts. 

Perl scripts (like python and tcl) require an interpreter program
(perl.exe) to run. Most perl issues arise from problems where perl
is not installed on the machine or Pi3Web can't find it.

On UNIX environments the OS looks at the first line for a #!<interpreter>
line and if it finds it it uses this as the interpreter for the file.
Windows does not do this and instead supports a more complex 'associations'
based solution. Some web servers explicitly support this (and Pi3Web
will support it soon as an option), but it is somewhat expensive to
inccur a file open, read and close on every CGI execution needlessly.

Solution:
--
There are many ways to get perl scripts to work according to your 
desires, here's the easiest:

i) Make sure perl is installed correctly on your machine, place the
following program in your cgi-bin directory, call it hello.pl:

----
print "Content-Type: text/plain\n\n";
print "Hello!\n"
---

Make sure you can execute it from the command line and cgi-bin 
directory using >perl hello.pl, if not fix your installation or your 
PATH

ii) By default this script will be executed as a perl script as
the default Pi3Web configuration executes files with a .pl extension
as 'perl <the full path to the file><the filename>'

iii) You can modify the Pi3Web configuration file so that CGI scripts with 
other extensions (or all cgi scripts) execute with perl:

	- open Conf\Config.pi3; find the line with 'Name StandardCGI'
	- Look down a few lines to the line 'CommandLineByExt .pl="perl %p%q"'
	- Add a new extension for a perl file (such as .cgi) by adding a
		a line like 'CommandLineByExt .cgi="perl %p%q"
	- ** OR ** Make all CGI programs execute with perl by removing all 
		'CommandLineByExt' lines and modify the line
		'DefaultCommandLine "%p%q"' to 'DefaultCommandLine "perl %p%q"'

Note that you can explicitly give the full path to the perl interpreter according
to this syntax where the PATH does not point to it like

		'CommandLineByExt .pl="d:\\perl\\bin\\perl.exe %p%q"'

or add special options to perl (such as taint-perl) like

		'CommandLineByExt .pl="perl.exe -T %p%q"'
or
		'CommandLineByExt .pl="d:\\perl\\bin\\perl.exe -T %p%q"'