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 dedicated 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:
my $query= new CGI;
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!