Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

CGI package recommendation

by BernieC (Monk)
on Jan 24, 2021 at 13:00 UTC ( #11127360=perlquestion: print w/replies, xml ) Need Help??

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

I last did a CGIed website something like 25 years ago -- AJAX was _just_ becoming popular! At the time I just used I now would like to do another -- it is for a simple but CGIed site.. I don't need AJAX or a DB interface or the like. Is there a better/more modern package for that kind of thing than just {NB: I remember almost nothing about using -- it's been a long time :) so I'd have to start by studying the POD docs anyway, so if there's something newer/easier/better I'd be happy to try it.}

Replies are listed 'Best First'.
Re: CGI package recommendation
by hippo (Chancellor) on Jan 24, 2021 at 13:58 UTC is still around and you can use that if you like - it will be fine for a low-traffic site. However it does still come with all the old HTML-generation functions (for backwards compatibility) and those are pretty much universally frowned on these days. I still create some sites using CGI (the protocol) but in most cases use one of the less heavy alternatives like CGI::Lite, CGI::Minimal, etc.

    If you are expecting it to be a high-volume site then something with a persistent back-end is going to be a better bet and there are a whole heap of options in that space, including using an FCGI wrapper around plain CGI scripts.


      > However it does still come with all the old HTML-generation functions (for backwards compatibility)

      You are right, I thought the code was out factored to


      But it seems that's only the documentation.


      Major correction 2 min after posting.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re: CGI package recommendation
by haukex (Bishop) on Jan 24, 2021 at 13:07 UTC
Re: CGI package recommendation
by 1nickt (Abbot) on Jan 24, 2021 at 13:49 UTC
      I'll check dancer2 out. I was surprised and pleased when I ssh'ed into my account on the shared webserver system:
      Warning: You do not have write permission for Perl library directories +. To install modules, you need to configure a local Perl library directo +ry or escalate your privileges. CPAN can help you by bootstrapping the loca +l::lib module or by configuring itself to use 'sudo' (if available). You may + also resolve this problem manually if you need to customize your setup. What approach do you want? (Choose 'local::lib', 'sudo' or 'manual') [local::lib]
      So I guess it'll be easy to install Dancer2 and play with it thanks...
Re: CGI package recommendation
by bliako (Prior) on Jan 24, 2021 at 13:22 UTC

    Although I was a big proponent of CGI because of its simplicity, I now use Mojolicious and I am very pleased with it. It's not that mojolicious is not "simple". It's that it needs to have its own webserver running. And it's prefered to have a webserver like nginx or apache proxy to that. Which is fairly simple if your host allows you access. But prohibitive in most free, share-hosting environments. I have switched to mojolicious when I got a VPS (paid server with full control via ssh access) instead of the free shared web-hosting.

      Thanks for the advice, but I'm using a shared-hosting environment and so I don't have my own webserver. I cannot even install modules. {although I'll ask the sysops if they are willing to install a CPAN module.} It'll be a very low traffic "site" and the web pages that the user will see will be pretty simple.

        It's worth asking Monks which are more experts with Mojolicious whether it can indeed be run in this environment without privileges/access and how. If not, the CGI is not bad at all and will be fine. But do read some more on caveats and alternatives: CGI::Alternatives

        I too operate a number of websites on shared hosting so feel your pain. For a long time I used CGI for processing input from a web form but never to generate the HTML.

        However, I ran into a number of random errors that I could not debug. I suspect they were more to do with the hosting environment than the module. The result was I wrote my own code to deal with form and image uploads instead.

Re: CGI package recommendation
by duelafn (Vicar) on Jan 24, 2021 at 20:15 UTC

    If you're looking for something with that same do-it-yourself feel, I've been using the following template for small one-off scripts. Not apppropriate for a site full of CGI, but if you have a static site with just a couple simple independent dynamic pages, it can be sufficient.

    use strict; use warnings; use 5.020; use utf8; use Plack::Request; use Encode; use JSON::XS; my $app = sub { my $req = Plack::Request->new($_[0]); my $input = decode 'UTF-8', $req->parameters->{'input'}; [ 200, [ 'Content-Type', 'application/json; charset=UTF-8' ], [ encode_json { output => uc $input } ] ]; }; # To run as a true CGI script, include after the sub: #use Plack::Handler::CGI; #Plack::Handler::CGI->new->run($app); # Or FastCGI for reverse proxy: # plackup -s FCGI --listen /tmp/fcgi.sock myapp.psgi # Or persistently for simple direct serve: # plackup --host --port 9090

    Good Day,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11127360]
Approved by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-03-04 00:38 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (97 votes). Check out past polls.