Perl CGI Quick Start on OEL
Hello Oracle Linux User! This Short Tutorial shows you Step-by-Step How to Getting-Started with Perl CGI Web Scripts on Oracle Enterprise Linux 6.x/7.x/8.x GNU/Linux Desktop/Server.
CGI.pm is a large and widely used Perl module for Programming Common Gateway Interface (CGI) web applications, providing a consistent API for receiving and processing user input.
-
Open a Shell Terminal emulator window
(Press “Enter” to Execute Commands)In case first see: Terminal QuickStart Guide.
-
Login as SuperUser.
sudo su
-
Install Perl & CGI.pm Module.
yum -y install perl perl-CGI
-
Enabling CGI in a Custom Directory
By Default it’s enabled only on the /var/www/cgi-bin location.
To make the Custom CGI Directory:mkdir /var/www/html/custom-cgi
Make an Apache Config File:
nano /etc/httpd/conf.d/cgi-enabled.conf
Append:
# create new # processes .cgi and .pl as CGI scripts >Directory "/var/www/html/custom-cgi"< Options +ExecCGI AddHandler cgi-script .cgi .pl >/Directory<
Ctrl+x to Save & Exit from nano.
-
Restart Apache.
service httpd restart
-
Set the New Rules for CGI
-
For OEL 7:
semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/custom-cgi
chcon -R -t httpd_sys_script_exec_t /var/www/html/custom-cgi
-
Instead, for OEL 6:
semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/custom-cgi
restorecon /var/www/html/custom-cgi
-
-
Testing a CGI Script.
nano /var/www/html/custom-cgi/index.cgi
Append something like:
#!/usr/bin/perl print "Content-type: text/html "; print "<html> <body>"; print "CGI Working on /var/www/html/custom-cgi"; print " </div>"; print "</body> </html>";
Then Save.
To Set Execution Permission:chmod 705 /var/www/html/custom-cgi/index.cgi
-
Achieve the SuperUser Session.
exit
-
Browse the CGI Page