How-to Enable Perl CGI on Red-Hat Linux

April 8th, 2017 by thelinuxevangelist

Perl CGI Quick-Start for RHEL




Hello Red-Hat Linux User! This Short Tutorial Shows You Step-by-Step How-to Getting-Started with Perl CGI Web Scripts on Red Hat Enterprise Linux 6.x/7.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 Red-Hat Linux - Featured
  1. On Desktop Open a Shell Terminal emulator window

    Perl CGI Quick-Start for Red-Hat Linux - Gnome3 Open Terminal
  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 RHEL 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 RHEL 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\n\n";
    print "<html>\n<body>\n";
    print "CGI Working on /var/www/html/custom-cgi";
    print "\n</div>\n";
    print "</body>\n</html>\n";
    

    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

(Visited 11 times, 1 visits today)
Share on Tumblr

Tags: , , , , , , , , , ,


Comments are disabled