Jul

9

This article teaches those who want to run Perl scripts from browser on Ubuntu Linux with Apache HTTP Server.

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:


Alias /perl/ /home/shi/Documents/Host/perl/

PerlModule ModPerl::Registry

<Location /perl/>
   SetHandler perl-script
   PerlHandler ModPerl::Registry
   #PerlHandler ModPerl::PerlRun
   Options +ExecCGI
   #PerlSendHeader On
</Location>

(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’.

Feel free to post a comment to let me know if you need any help!



Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

3 Comments so far

  1. jakub88 on July 25, 2008 10:22 pm

    have been trying to install Perl for a month from now, finally get it installed and configured correctly by following your article, great article!

  2. Jose Esquivel ( Costa Rica ) on August 13, 2008 1:53 pm

    Hi,

    I started at my new job 2 days ago, I was told to learn a little bit of Perl, as I like to do more I proposed to do also do some Perl on Web and this tutorial is awesome, it practically took me all the way to set my environment. One of the best tutorials, very direct, easy to follow and in the end you get what you specked

  3. admin on August 17, 2008 9:08 am

    Hi, guys, i am so glad that it helps!

Sponsors




Links