• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Having .cgi treated as Perl scripts

Hello,

I am using a local setup with native Windows versions of Apache and Perl, in order to work on web sites locally, which I then upload to my Unix web host. It is working fine, but there is one last thing to solve.

I am using some files with .cgi extension (in the setup of my web host, these can sit anywhere, no cgi-bin directory is used), which happen to be Perl scripts (all of them).

Obviously it won't work "out of the box", since the #! line needed on my Unix host won't help Windows Apache to find Windows Perl.

So what I was thinking to do was to instruct Windows Apache (local) to treat all .cgi scripts as Perl scripts. Had no luck doing this so far, though.

Could anyone tell me the necessary and sufficient changes to be done in httpd.conf to achieve that result (OR possibly provide another route to solve the same problem)?

Thanks!

Jacques

PS: FYI, I am using the Apache2Triad pack, pretty much out of the box (this is a packing of Windows Apache, and supporting Windows native software).
0
JacquesDP
Asked:
JacquesDP
  • 8
  • 4
  • 3
3 Solutions
 
JacquesDPAuthor Commented:
Note : the fact that my Perl CGI scripts end in .cgi is a contraint from my web host (i.e., I can't change them to .pl).
0
 
ronan_40060Commented:
Hello Jacques
There are Three ways you can tell Apache to execute all files with .pl extension

1 >  you need to add the following directive to httpd.conf:
  AddHandler cgi-script .cgi .pl
This tells Apache that files with extensions .cgi or .pl must be executed.

2 > This following line should be the first line in your scripts:
#!c:/perl/bin/perl.exe
This line tells Apache that this script should be run with perl.exe.
Note that the path to perl.exe must be valid.

3 > If your on  Windows just after your  AddHandler cgi-script .cgi .pl line add the following line  
ScriptInterpreterSource Registry
This tells Apache to look up the association in the windows registry instead of in the shebang line of your scripts.

After making necessary change , save the config file and restart the Apache
Good Luck

Bon Weekend
Ronan
0
 
JacquesDPAuthor Commented:
Hi Ronan,

Thanks for your answer, however it doesn't really address my question.

First, my goal is not to have .pl files interprteted as Perl scripts, but .CGI files to be interpreted as Perl scripts.

Your way 1 is not useful regarding the .pl file (I don't have .pl file, since my web host forces me to have Perl script with the .cgi extension).

Your way 2 is what I need to avoid, in order to be able to upload the file untouched on my Unix host (see my initial message).

Your way 3 won't work either, since the file is .cgi and not .pl.

Another bit of information is that my local, windows native version of Perl is ActivePerl.

Thanks,

Jacques
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
ronan_40060Commented:
OK
Then just put
 the following directive to httpd.conf:
  AddHandler cgi-script .cgi
This tells Apache that files with extensions .cgi  must be executed.

let me know
Ronan
0
 
JacquesDPAuthor Commented:
Hi Ronan,

I have this already. But it will only work if I have a correct shebang line at the beginning, namely

#!C:/apache2triad/perl/bin/perl.exe

But if I put that, then I cannot upload my files to my Unix web host.

Hence my question.

Thanks,

Jacques
0
 
ronan_40060Commented:
Well on Unix host
your path would change you can not use the windows path to a Unix Host
change the path to Unix perl path in shebang line
0
 
JacquesDPAuthor Commented:
Hi Ronan,

The thing is, I want the SAME files (unchanged) to work on both plaform (the upload is an automated and frequent process on many files). This is really what my question is about.

The Unix  Apache will rely on the shebang line, but I can probaly tweak my local Windows Apache config so that .cgi files be treated as Perl script regardless of the  (Unix) shebang line, can't I?

Jacques
0
 
ronan_40060Commented:
As far as I know you need to have your cgi files named as .pl files to be treated as perl scripts.
Also you have Active Perl installed on your windows. you need to have your cgi named as .pl
0
 
JacquesDPAuthor Commented:
As I said above, this is not an option for me, since my web host forces me to have .cgi extension on all my scripts. I am pretty sure there is an easy solution. If no one can offer it to me here, I will do more research on my side.
0
 
JacquesDPAuthor Commented:
As far as I'm concerned, the question has not been answered. (In fact, I now change manually the shebang line before uploading, and what I was asking is how to avoid that, and have the exact same .cgi perl script work on both platforms.)
0
 
periwinkleCommented:
FWIW, I'm not certain that there is a possible  answer for you -- What Ronan is saying is that Windows won't recognize the script as a perl script unless you use the .pl extension, and you're saying that your provider won't accept .pl scripts, only .cgi extension ones.

Can you override your apache settings on the Linux server by creating a .htaccess file that states:

AddHandler cgi-script .pl

and then use the .pl extension?

0
 
JacquesDPAuthor Commented:
Hi periwinkle,

I can have a .pl perl script on the web host (this is a new info, I was ruling this out earlier). Now, can I manage for this same .pl perl script, with the same shebang line (necessarily wrong for one of the two platforms), to work on both platform?

Thank you

Jacques
0
 
periwinkleCommented:
If I understand Ronan's comments above, if you modify your local (Windows) Apache configuration by:

3 > If your on  Windows just after your  AddHandler cgi-script .cgi .pl line add the following line  
ScriptInterpreterSource Registry
This tells Apache to look up the association in the windows registry instead of in the shebang line of your scripts.

You will then be able to use the Linux convention in the shebang line, and upload to both and have both work.
0
 
JacquesDPAuthor Commented:
Heh. This works :-)

Though this does not answer my original question in the way it was originally phrased, it still sort of solves my problem. I am sharing the points between you both.

Thanks a lot, both for the original answer from Ronan and the further explanation from periwinkle.

Jacques
0
 
periwinkleCommented:
Jacques - Glad to hear that this solves your problem - good luck with your work, and best wishes for a happy holiday!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now