sudo apt-get install libapache2-mod-perl2
(if Ubuntu Server
use aptitude install)sudo a2enmod perl
)mkdir ~/www/cgi-bin
(it could be anywhere, just take it as an example)/etc/apache2/sites-enabled/000-default
file before </VirtualHost>
line.
# Use 'ModPerl' module to process '.pl' and '.cgi' file
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
# Use '/home/www/cgi-bin/' as a CGI Directory
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory "/home/www/cgi-bin/">
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>
sudo service apache2 restart
- Create file
test.pl
in/home/www/cgi-bin/
:
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++)
{
print $i."<br />";
}
- Note 1:
#!/usr/bin/perl -w
is used to locate the perl parser which could be located bywhich perl
.- Note 2: code
print "Content-type: text/html\r\n\r\n";
is required to make it a valid CGI program.