Perl acctually works “out of the box” in Apache 2 installed on Ubuntu 8.04 JeOS. I found much confusion on this subject while browsing the Internet so I thought I’d post a simple HOWTO to get the first script running.
First you need a Ubuntu 8.04.1 JeOS server with a LAMP installation, see my previous guide on how to make one.
The first thing that can be confusing is where to find the right configuration files for Apache, while not needed for this guide I thought I’d post the current version for this guide here. A good overview of all distributions / versions can be found over at the Apaches wiki.
Debian, Ubuntu (Apache 2):
ServerRoot :: /etc/apache2
DocumentRoot :: /var/www
Apache Config Files :: /etc/apache2/apache2.conf
:: /etc/apache2/ports.conf
Default VHost Config :: /etc/apache2/sites-available/default, /etc/apache2/sites-enabled/000-default
Module Locations :: /etc/apache2/mods-available, /etc/apache2/mods-enabled
ErrorLog :: /var/log/apache2/error.log
AccessLog :: /var/log/apache2/access.log
cgi-bin :: /usr/lib/cgi-bin
binaries (apachectl) :: /usr/sbin
start/stop :: /etc/init.d/apache2 (start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean)
Now as I said, Perl is allready working so we just have to find it in our system! As since in the chart above the cgi-bin is located in /usr/lib/cgi-bin. Here we want to put a Perl Hello World script.
sudo nano /usr/lib/cgi-bin/test.pl
In the script I type the following very standard Hello World script:
#!/usr/bin/perl -w
print “Content-type: text/plainnnHello World!n”
We need to make it executable so we chmod it:
sudo chmod 755 /usr/lib/cgi-bin/test.pl
To make sure it’s working a good tip is to try it at the command line first to check for any spelling errors (especially in the header, errors there will lead to a 500 internal server error response).
perl /usr/lib/cgi-bin/test.pl
If it runs and returns the content-type line, two new lines and a hello world then we’re set! Browse to the IP of the server, in my case it’s 192.168.0.16 so I enter:
http://192.168.0.16/cgi-bin/test.pl
Hello World!
Hey thanks!
Clear and simple: this is just the information I was looking for tonight (in contrast to the the not-so-clear info I’m getting from the candidates at Canadian election debate).
Jean-Philippe Valois
Thanks for the quick guide. This helped. FYI – I installed apache2 via apt-get, on a non LAMP Ubuntu 8.04 distro, and the default configuration was the same.
Hello, Thank for the tutorial, finally I do understand why perl was not running from /var/www
Can someone tell me how can I run perl script from document folder? (/var/www)
I have found a lot of different article but non of them was correct.
Thanks.