1, the Linux system generally with Perl
Can run the program in:/usr/bin/perl
2. Perl Test Procedure
Copy Code code as follows:
#!/usr/bin/perl-w
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:
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/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
cgi_test.pl
Copy Code code as follows:
#!/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/>";
Attention:
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.