How to enable apache2 to run the perl cgi program in cgi Mode

Source: Internet
Author: User

1. linux generally comes with perl
You can run the program in:/usr/bin/perl

2. perl Testing Program

Copy codeThe Code is as follows :#! /Usr/bin/perl-w
Use warnings;
Print "Hello, Perl works! ";

Name it test. pl.

Locate the directory in the terminal. If you input perl test. pl and perl to work normally, the output is displayed.
Hello, Perl works!

3. Let apache2 support perl in cgi Mode
A. After apache2 is installed,
The configuration file is located in the/etc/apache2 directory, mainly apache2.conf.
However, you can modify the default value under sites-available;
After the modification is complete, restart apache2. You need to enter/etc/init. d/apache2 and then add the parameters stop, start and restart.

B. modify the configuration file of apache2 to support perl in cgi Mode.
Modify

Copy codeThe Code is as follows: ScriptAlias/cgi-bin // var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride all
Options + ExecCGI-MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all
</Directory>

Set the directory/cgi-bin/to/var/www/cgi-bin/
(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 extensions (cgi and pl extensions are supported by default)

4. Compile a cgi Test Program
Cgi_test.pl

Copy codeThe Code is as follows :#! /Usr/bin/perl-w
Use warnings;
Use CGI qw (: standard );
#! Must use 'my 'to define a variable
Print header;
My $ now_string = localtime ();
Print "<B> Hello, CGI using Perl! </B> <br/> It's $ now_string NOW! <Br/> ";

Note:
A. copy the cgi_test.pl program to the/var/www/cgi-bin/directory.
B. You also need to modify the cgi_test.pl permission. Otherwise, the following error may occur:
(13) Permission denied: exec of '/var/www/cgi-bin/cgi. pl' failed
Sudo chmod 755 cgi_test.pl

5. In summary, follow the methods described above:
A. the perl program runs normally in Linux.
B. apache2 supports perl cgi programs with cgi
If an error occurs, you can view the erro log file of apache2 in/var/log/apache2/error. log to further query and troubleshoot the error.

C. On the other hand, you can write the cgi perl program first, and check whether the program itself is wrong under the command line perl cgi_test.pl.
If there is no error, you can locate the problem as apache2's support for the perl cgi program.

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.