6

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

Rahul
  • 364
  • 3
  • 8
  • 21
  • I checked my apache error logs and found its taking a different path to the file /usr/lib/cgi-bin/perl_1.pl (i,e ubuntu's default location for cgi scripts), then i changed the file location from /var/www/cgi-bin/perl_1.pl to this location, the script is running fine... but how to change that directory or how can i add ExecCgi to my created directory???? – Rahul Jan 19 '12 at 04:42

3 Answers3

6

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.

Jarmund
  • 3,003
  • 4
  • 22
  • 45
  • 1
    Also, make sure the file permissions are OK. eXecute permission should be set for web server user (e.g. `chmod u+x perl_1.pl`). – pwes Jan 18 '12 at 14:03
  • Thanks for your reply. I tried by directly executing the file. But then it says 404: The requested URL /cgi-bin/perl_1.pl was not found on this server. And i don't have much knowledge about the configurations if you please kindly let me know in a bit details or steps. Thanks – Rahul Jan 18 '12 at 14:46
3

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>
Ricky Levi
  • 7,298
  • 1
  • 57
  • 65
0

If you are not tied to apache or can run these scripts on different port then you can use Plack/PSGI toolchain that have solutions to run old CGI scripts as PSGI applications. See Running CGI scripts on Plack for several ways to do it.

ruz
  • 482
  • 2
  • 7
  • I am a beginner in perl was just writing my test scripts. And am unable to get the o/p in browser although i can execute it from "padre" editor. Thanks – Rahul Jan 18 '12 at 14:50