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).
JacquesDPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.