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.