Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a perl script in localhost?

I had already installed Apache. I am using PHP for my scripting in localhost. Need to know how to run the perl script. I have installed sudo aptitude install libapache2-mod-perl2 I have created a directory name cgi-bin in my /var/www/cgi-bin there inside this folder i have kept my perl script perl_1.pl The directory permissions are given. What more i have to do to run the script???? i just type http://localhost/cgi-bin/ and i got error 403 You don't have permission to access /cgi-bin/ on this server. please help!!

Thanks

like image 636
Rahul Avatar asked Feb 21 '23 19:02

Rahul


2 Answers

you can't read the cgi-bin contents. You must refer directly to one of the scripts in it, in this case: http://localhost/cgi-bin/perl_1.pl

Outside of that, ensure that your cgi-bin/ directory is actually treated as such in httpd.conf.

Oh, and in case you stumble on 500 afterwards: make sure that your perl script prints a valid HTTP header. This can easily be achieved by:

use CGI qw(:standard);
print header();

And as Pwex pointed out: make sure your script has the executable bit set.

chmod 755 perl_1.pl

...should work in most cases

Additionally, for future reference it is worth mentioning mod_perl, as it is a natural next step after getting the basics of cgi + perl + apache down. Going into detail about it would be beyond the scope of this answer, but I thought I'd mention it so that you know where to go next when you've got the basics nailed down as well as seen the limitations of cgi.

like image 123
Jarmund Avatar answered Feb 24 '23 09:02

Jarmund


How's your Apache configured ? Did you make sure you're telling the Apache to execute CGI script in the cgi-bin directory ?

Something like:

ScriptAlias /cgi-bin/ "/var/www/website/cgi-bin/"
<Directory "/var/www/website/cgi-bin/">
                Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

                ...
</Directory>
like image 24
Ricky Levi Avatar answered Feb 24 '23 09:02

Ricky Levi