ajkessel has asked for the wisdom of the Perl Monks concerning the following question:

Can someone point me to best practices for packaging up a CGI perl script and supporting files? I found this thread -- Packaging up a Complete Perl Program -- which asks how best to package a program (rather than a module). What about a perl program where the script is either going to go into ~/public_html/cgi-bin (or whatever the user's cgi directory is) -- *or* systemwide into /usr/lib/cgi-bin? Supporting executables that are not run from the webserver would go into ~/bin or /usr/bin; and where should documentation (other than built-in POD documentation) go for per-user installation?

Many CGI scripts are like this: either installed systemwide or per-user (blogging packages, for example). Is there a good systematic way to do this? Ideally the user would just make install and it would Just Work, but there probably needs to be some sort of decision, either presented to the user or in the make arguments, as to where the files are to be installed.

  • Comment on Best practices for packaging CGI scripts

Replies are listed 'Best First'.
Re: Best practices for packaging CGI scripts
by sgifford (Prior) on Aug 08, 2005 at 17:59 UTC

    Creating a CPAN-style package works pretty well for this. The installer can use standard mechanisms or their CPAN setup to control where things are installed, and dependencies are managed automatically.

    Another option is PAR, which can package everything into one file to be installed and run.

Re: Best practices for packaging CGI scripts
by bsb (Priest) on Aug 09, 2005 at 06:16 UTC
    Check how others have done it on CPAN. CGI::Kwiki for example.
Re: Best practices for packaging CGI scripts
by westernflame (Sexton) on Aug 08, 2005 at 19:09 UTC
    The type of packaging required for CGI scripts is dependant on who the script is intended for. What level of skill can you expect from users?
      My intended users would range from "power users" who run their own webservers to users with more limited skills who would know enough to find a script on freshmeat and follow basic instructions about editing the config file with a text editor. Comparable to the level of skill of a typical user who was going to install their own blogging software on their webserver account (rather than use something like blogger.com). As I mentioned above, I'd like to have a "systemwide" installation option along with the per-user installation.
        Your power user and your user with limited skill will have different levels of access to the server. A CPAN module is certainly the best way but completely impossible for many users. Without shell access CPAN installation is difficult or impossible. Considering which directories to put files is academic if the user does not have access to anything but a cgi-bin. Some hosts I have come across will even deploy installations of Perl that won’t accept relative file paths.

        The most important thing for getting CGI scripts to run on these limited environments is simplicity. They should not require additional CPAN modules. In my opinion the best approach is using an installation script to retrieve variables from the user. The script will be as simple as possible to ensure that it will run in any environment. The users variables can then be entered and checked before more complex parts of the program are used. Far too many perl CGI scripts simply stop working when they have incorrect user entered variables. With respect to system wide installation CPAN installation is certainly the best way to go.