How to Enable Perl CGI on Oracle Linux

April 8, 2017 | By the+gnu+linux+evangelist.

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.

Perl CGI Quick Start for Oracle Linux - Featured
  1. Open a Shell Terminal emulator window
    (Press “Enter” to Execute Commands)

    Perl CGI Quick Start for Oracle Linux - GNOME3 Open Terminal

    In case first see: Terminal QuickStart Guide.

  2. Login as SuperUser.

    sudo su
  3. Install Perl & CGI.pm Module.

    yum -y install perl perl-CGI
  4. 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.

  5. Restart Apache.

    service httpd restart
  6. 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
  7. 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
  8. Achieve the SuperUser Session.

    exit
  9. Browse the CGI Page

    http://localhost/custom-cgi/index.cgi


QuickChic Theme • Powered by WordPress