2024年10月25日 星期五

Execute Perl WEB CGI in Oracle Linux 9


dnf install oracle-epel-release-el9.x86_64

dnf install  mod_perl

dnf install  perl-CGI perl-CPAN perl-HTTP-Tiny.noarch perl-JSON perl-Encode.x86_64 


vi /etc/httd/conf.d/perl.conf


#PerlModule ModPerl::Registry

##PerlModule ModPerl::PerlRun


Alias /cgi /var/www/html/cgi

<Directory /var/www/html/cgi>

    #SetHandler perl-script

    AddHandler perl-script .pl

    AddHandler perl-script .cgi

    PerlResponseHandler ModPerl::Registry

    ## PerlResponseHandler ModPerl::PerlRun

    PerlOptions +ParseHeaders

    Options +ExecCGI

    Order allow,deny

    Allow from all

</Directory>


systemctl restart httpd 


Test reference


https://hostingultraso.com/help/centos/implementing-cgi-perl-ruby-centos

Creating your first Perl CGI script

Now create the following Perl CGI script file by opening the new file vi /var/www/cgi-bin/perl-test.cgi and putting in the following content:
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
print header;
my $now = localtime;
print start_html(-title=>'Server time via Perl CGI'),
h1('Time'), p("The time is $now"),
end_html;



https://www.geeksforgeeks.org/perl-get-vs-post-in-cgi/


Example:

<html> 
<head></head> 
<body> 
<b> Search Your Query:</b><br> 
<FORM action="Gfg_get.pl" method = "GET"> 
<input type="text" name="q" size="20" maxlength="120"> 
<input type="submit" value="Search"><br> 
<input type="radio" name="l" value="Web" checked>Web 
<input type="radio" name="l" value="India">IND 
</FORM> 
</body> 
</html> 




Perl-CGI script for the above GET method form:


#!"c:\xampp\perl\bin\perl.exe" 
    
$buffer = $ENV{'QUERY_STRING'}; 
#split information into key/value pairs 
@pairs = split(/&/, $buffer); 
foreach $pair (@pairs)  
    ($name, $value) = split(/=/, $pair); 
    $value =~ tr/+/ /; 
    $value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg; 
    $value =~ s/~!/ ~!/g; 
    $FORM{$name} = $value; 
  
$SearchTerm = $FORM{'q'}; 
$Location = $FORM{'l'}; 
  
print "Content-type:text/html\r\n\r\n"; 
print "<html>"; 
print "<head>"; 
print "<title>GeeksForGeeks - Get Method</title>"; 
print "</head>"; 
print "<body>"; 
print "<h3>Hello You searched '$Location' for '$SearchTerm'<br> 
Few Matches Found!<br> 
<br> 
Match 1<br> 
Match 2<br> 
Match 3<br> 
Match 4<br> 
etc.....</h3>"; 
print "</body>"; 
print "</html>"; 
  
1; 



My LAB Test Demo