Configure Apache to support CGI

Source: Internet
Author: User

Recently in building Gitweb, Apache is needed to support Perl (CGI enabled)

Find many methods on the Internet, many failed, and finally summed up a successful method of configuration:

First, has been installed on the Apache server

Second, edit/etc/apache2/apache2.conf

First configure Apache support for CGI, plus the following configuration:

LoadModule cgi_module/usr/lib/apache2/modules/mod_cgi.so


Then configure a directory to execute the CGI program, here I take the/var/www directory as an example:

<Directory/var/www/>
        Options Indexes followsymlinks execcgi   #加上ExecCGI to support CGI programs
        allowoverride None
        Require All granted
        AddHandler cgi-script. exe. pl. CGI   #添加cgi程序将要处理的后缀名
</Directory>

End

We create a file in the/var/www directory, test.cgi:

#!/usr/bin/perl-w use
warnings;
Use CGI QW (: standard);
#! Must use ' I ' to define a variable
print header;
My $now _string = LocalTime ();
Print "<b>hello, CGI using Perl!</b><br/>it ' s $now _string now!<br/>";

Restart Apache, Access: localhost/test.cgi can see the content of the page output, to this, Apache support CGI configuration success



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.