1. First, you need to install apache2 by executing the following command from the terminal:
sudo apt-get install apache2
2. Now you can install mod_perl by executing the following command from the terminal:
apt-get install libapache2-mod-perl2
3. If you know how to set up a local server directory to let files like example.html running from browser like http://localhost/example.html or you previously installed LAMP, then you can read on, if not, please read this article first before continue.
4. Now you may need to edit Apache Configuration file in order to tell Apache Perl where your .pl script is located, so that the server can execute it as Perl script. So let’s say if you put your Perl script example.pl inside a folder located at your defined local server directory for instance /home/shi/Documents/Host/perl/example.pl, you need to open apache2.conf:
sudo gedit /etc/apache2/apache2.conf
add in the code:
view source
print?
01.Alias /perl/ /home/shi/Documents/Host/perl/
02.
03.PerlModule ModPerl::Registry
04.
05.
06. SetHandler perl-script
07. PerlHandler ModPerl::Registry
08. #PerlHandler ModPerl::PerlRun
09. Options +ExecCGI
10. #PerlSendHeader On
11.
(change the line /home/shi/Documents/Host/perl/ to your server directory name)
And now restart your server by running the following command in terminal:
sudo /etc/init.d/apache2 restart
Now write a test.pl file with the test script below:
#!/usr/bin/perl
use CGI;
my $query= new CGI;
print $query->header;
print "hello people in my head\n";
set the test.pl file permission to 755 and put it in your local server directory and type the url path in the browser and you should see the message: ‘hello people in my head’.
No comments:
Post a Comment