How to Enable Perl CGI on CentOS Linux

April 8, 2017 | By the+gnu+linux+evangelist | Filed in: Tutorial.

Perl CGI Quick Start for CentOS

You are Welcome! This Short Tutorial shows you Step-by-Step How to Getting-Started with Perl CGI Web Scripts on CentOS 6.x/7.x/8.x/8-Stream/9-Stream GNU/Linux Desktop/Server. 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.

How to Install EPEL Repository on CentOS Stream 9
  1. On Desktop Open a Shell Terminal emulator window
    (Press “Enter” to Execute Commands)

    Perl CGI Quick Start for CentOS - Open Terminal
  2. Login as SuperUser.

    sudo su
  3. Install Perl & 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


    # create new
    # processes .cgi and .pl as CGI scripts
    >Directory "/var/www/html/custom-cgi"<
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl

    Ctrl+x to Save & Exit from nano.

  5. Restart Apache.

    service httpd restart 
  6. Set the New Rules for CGI

    • For CentOS 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 CentOS 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:

    print "Content-type: text/html
    print "<html>
    print "CGI Working on /var/www/html/custom-cgi";
    print "
    print "</body>

    Then Save.
    To Set Execution Permission:

    chmod 705 /var/www/html/custom-cgi/index.cgi
  8. Achieve the SuperUser Session.

  9. Browse the CGI Page


Thanks to:

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

QuickChic Theme • Powered by WordPress