A way to get apache2 to run Perl CGI programs in CGI _perl

Source: Internet
Author: User

1, the Linux system generally with Perl
Can run the program in:/usr/bin/perl

2. Perl Test Procedure

Copy Code code as follows:

Use warnings;
Print "Hello, Perl works! ";

Named test.pl

Under the terminal, navigate to the directory, and enter the Perl Test.pl,perl to work correctly, showing the output
Hello, Perl works!

3. Allow Apache2 to support Perl in a CGI way
A. After the installation of Apache2 is complete,
The configuration file is located in the/etc/apache2 directory, mainly apache2.conf.
But the modification of the time can mainly modify the sites-available below the default;
After the modification is complete, restart Apache2, and you need to enter/etc/init.d/apache2 to add the parameters stop, start, restart.

B. Modifying the Apache2 profile so that it supports Perl in a CGI way
Modify the sites-available in the default under

Copy Code code as follows:

<directory "/var/www/cgi-bin" >
AllowOverride All
Options +execcgi-multiviews +symlinksifownermatch
Order Allow,deny
Allow from all

Set the directory/cgi-bin/corresponds to/var/www/cgi-bin/
(That is, the http://localhost/cgi-bin/directory is a CGI script)
At the same time modify allowoverride, Options, order, allow and so on.
You can also add
AddHandler cgi-script. cgi. pl

Custom supported suffixes (CGI and PL suffixes are supported by default)

4. Write CGI test program

Copy Code code as follows:

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/>";

A. Need to copy the cgi_test.pl program to the/var/www/cgi-bin/directory
B. You also need to modify the permissions of the program cgi_test.pl, otherwise the following similar error occurs:
(13) Permission denied:exec of '/var/www/cgi-bin/cgi.pl ' failed
sudo chmod 755 cgi_test.pl

5, in summary, according to the method described above:
A. Perl programs run normally under Linux.
B. Apache2 to support Perl CGI programs with CGI
Encountered errors can be viewed, apache2 erro log files, located/var/log/apache2/error.log further queries and troubleshooting errors.

C. Another aspect, for CGI Perl programs can be written first, at the command line Perl cgi_test.pl to see if the program itself is wrong.
If it's not wrong, you can completely position the problem as apache2 support for Perl CGI programs.

Related Article

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.