Perl Setup
Perl Setup for ILE Apache on IBM i
Note: Module MOD_PERL is not available on IBM i.
Note: V7R2 Apache bug for PASE CGI, IBM understands and working the issue (PTF future).
How to configure Perl support in ILE Apache using a PASE CGI implementation.
Software Requirements
IBM i V5R4M0
5722SS1 Option 33 - Portable App Solutions Environment (PASE)
5722DG1 - IBM HTTP Server for i5/OS
5799PTL - IBM Tools for Developers for i5/OS
IBM i 6.1
5769SS1 Option 33 - Portable App Solutions Environment (PASE)
5769DG1 - IBM HTTP Server for i5/OS
5799PTL - IBM Tools for Developers for i5/OS
IBM i 7.1
5770SS1 Option 33 - Portable App Solutions Environment (PASE)
5770DG1 - IBM HTTP Server for i
5799PTL - IBM Tools for Developers for i5/OS
Necessary Components
1) /www/<instance>/conf/httpd.conf ILE Apache configuration file 2) /QOpenSys/perl-bin/ directory for perl cgi wrapper 3) /QOpenSys/perl-bin/perl-cgi perl cgi wrapper that will exec $ENV{PATH_TRANSLATED}; 4) /QOpenSys/perl-bin/perl-htdocs directory for perl scripts 5) /QOpenSys/perl-bin/perl-htdocs/helloworld.pl example "hello world" perl script 6) /QOpenSys/usr/bin/perl symbolic link to the perl installation directory
Step 1: Update the ILE Apache instance’s configuration file to resolve Perl scripts using a Perl CGI Wrapper program and to tell it where Perl scripts are located.
Note: Perl scripts need to be located somewhere in the /QOpenSys file system since the Perl CGI wrapper program executes in PASE.
# Update the ILE Apache instance's configuration file to resolve Perl scripts using a Perl CGI wrapper program. ScriptAlias /perl-bin/ /QOpenSys/perl-bin/ AddType application/x-httpd-perl .pl Action application/x-httpd-perl /perl-bin/perl-cgi <Directory /QOpenSys/perl-bin> Options +ExecCGI order allow,deny allow from all </Directory> # Update the ILE Apache instance's configuration file to tell it where Perl scripts are located. Alias /perl-htdocs /QOpenSys/perl-bin/perl-htdocs <Location /perl-htdocs> Order deny,allow Allow from all </Location>
Step 2: Create the necessary directories in the /QOpenSys file system in a PASE for i terminal session (CALL QP2TERM).
> mkdir -p /QOpenSys/perl-bin/perl-htdocs
Step 3: Create the perl CGI wrapper (/QOpenSys/perl-bin/perl-cgi) that will exec the value of the $ENV{PATH_TRANSLATED} CGI environment variable.
Note: If everything is configured correctly, exec will transfer to new program (i.e. the value in $ENV{PATH_TRANSLATED}) and none of the “debug” CGI environment variables will display in the browser.
#!/QOpenSys/usr/bin/perl exec $ENV{PATH_TRANSLATED}; print "Content-Type: text/html;\r\n\r\n"; print "<html>\n"; print " <head>\n"; print " <title>View CGI Environment Variables</title>\n"; print " </head>\n"; print " <body bgcolor=white>\n"; print " <h1>$ENV{PATH_TRANSLATED}</h1>"; print " <h2><font face=helv color=cc9900>CGI Environment Variables</font></h2>\n"; print " <table cellpadding=3 cellspacing=0 border=1>\n"; foreach $key (sort(keys %ENV)) { print " <tr><td align=right>$key:</td><td> $ENV{$key}</td></tr>\n"; } print " </table>\n"; print " </body>\n"; print "</html>\n"; exit(0);
Step 4: Create a symbolic link in /QOpenSys pointing to the perl installation directory in a PASE for i terminal session (CALL QP2TERM).
> ln -sf /QIBM/ProdData/DeveloperTools/pase/bin/perl /QOpenSys/usr/bin/perl
Step 5: Create the example “Hello World” (helloworld.pl) perl script.
Note: The helloworld.pl script needs to exist in /QOpenSys/perl-bin/perl-htdocs according to the Apache configuration above.
#!/QOpenSys/usr/bin/perl print "Content-Type: text/html;\r\n\r\n"; print "Hello, world!\n";This script can be accessed similar to this:
http://<hostname>:<port>/perl-htdocs/helloworld.pl
Reminder
Files processed by PASE need to have their lines ended with a LF (hex 0A) character rather than with CRLF (hex 0D0A) characters. The use of a LF character at the end of lines is the norm for Unix/Linux. The use of CRLF at the end of lines is the norm for Windows.