PDA

View Full Version : How to enable Perl-CGI in a Preferred Web Hosting account



fadein
02-07-2012, 06:48 PM
I signed up for the Preferred Web Hosting package, and one of the advertised features is Perl-CGI. However, my own Perl scripts always yield the dreaded [an error occurred while processing this directive] when I include them in my .shtml page. They all produce valid output when run from the shell.

Even more puzzling to me is the fact that the cPanel-generated CGI programs work just fine, and produce the expected output both from the shell and my .shtml. I can place my own program side-by-side with the one cPanel generates in both the cgi-bin and scgi-bin directories and my programs will fail every time.

What do I need to do to allow my own custom CGI programs to run?

wildjokerdesign
02-08-2012, 08:21 AM
What permissions do you have your programs set to? They need to be executable. 755 Other common issues would be an incorrect path to perl or MS style new lines in your code.

The first is pretty easy, make sure your first line is #!/usr/bin/perl

The second is really pretty easy also. Make sure you don't use something like Word to create or edit your scripts. Use a plain text editor. There are two of them in my signature that are free to download. :)

There are other things that can be the problem but I bet it is one of those.

fadein
02-08-2012, 04:36 PM
What permissions do you have your programs set to? They need to be executable. 755 Other common issues would be an incorrect path to perl or MS style new lines in your code.

The first is pretty easy, make sure your first line is #!/usr/bin/perl

The second is really pretty easy also. Make sure you don't use something like Word to create or edit your scripts. Use a plain text editor. There are two of them in my signature that are free to download. :)

There are other things that can be the problem but I bet it is one of those.

Thanks for the tips, wildjokerdesign, but it turns out they weren't the problem.
The perms were already 755, and my shebang line is correct. I wrote the script in the shell with Vim.

I finally discovered, by way of RTFM, that I needed to create public_html/cgi-bin/.htaccess with the following contents:

Options ExecCGI Includes
SetHandler cgi-script

I had assumed that such a configuration would have already existed in my cgi-bin/ directory. But we all know what they say about assuming, don't we?

wildjokerdesign
02-09-2012, 07:36 AM
That is really odd. I have never had to do that on a WH cPanel account. Also the directives you described in your .htaccess had to already be configured elsewhere or the pre-installed scripts would not have worked. Did you send in a support ticket on this issue? I would even now that you have it working because something seems odd and maybe there is an underlying issue that WH needs to look at on your account.

fadein
02-10-2012, 10:23 AM
That is really odd. I have never had to do that on a WH cPanel account. Also the directives you described in your .htaccess had to already be configured elsewhere or the pre-installed scripts would not have worked. Did you send in a support ticket on this issue? I would even now that you have it working because something seems odd and maybe there is an underlying issue that WH needs to look at on your account.

I'll do that.

ifurniss
02-13-2012, 08:30 AM
Sounds like you got things worked out, but we can definitely assist more through a ticket on this matter.

fadein
02-17-2012, 09:40 PM
Sounds like you got things worked out, but we can definitely assist more through a ticket on this matter.

Done. It's ticket #552694.

Lucky
04-02-2013, 06:16 PM
Awesome! I've been struggling with this for hours. Adding:

Options ExecCGI Includes
SetHandler cgi-script

to the htaccess file fixed the problem like magic --thanks!

-------------------------------------------------------

Well, it turns out that while adding those 2 lines to the htaccess file in the main directory did cause the shtml files to work and pull text from files in the cgi-bin like they're supposed to, it caused the standard html pages to stop working! I guess I need to study this when I have time and not rush things.

wildjokerdesign
04-03-2013, 07:10 AM
.shtml is a different handler then .cgi files. You are looking fro SSI or server side include I think. The thing is this should be already set up for you. Not what may be happening is that if you put your .shtml files in the main web root of your site and then the ones you want included in the cgi-bin there may be something about the cPanel setup that keeps that from happening. the cgi-bin is for perl or cgi scripts not for files you would want included vie SSI or files with the .shtml

If you can give some more details on what you are trying to do with examples (even if you cut out the bulk of content in files) I should be able to help you out.

Lucky
04-03-2013, 05:48 PM
Hi Shawn,
They should be paying you for all the help you dole out! BTW, the rack builder is still running strong. It will eventually be moved to this new VPS but that's a project for another day. :)

My problem now is that my page at which is in the main directory (not cgi-bin) has a line in it that calls for text to be inserted on a rotating basis, a new block of text every day. That line is:

<!--#include virtual="/cgi-bin/rotate.cgi" -->

the script named in the line above (permission 755) works with 2 other files which are also in the cgi-bin and somehow sends the appropriate block of text back to the shtml page.

the other files are rotate.txt (holds all the text, 744)
and rotate_data.txt (a file for temporary storage, 766)

I am pretty sure that the paths and permissions are correct because when I inserted the two lines mentioned above into the htaccess file, it worked! And so did the rest of the series that function similarly. The problem (other than not really knowing what I'm doing) is that it made the normal static html pages STOP working! If I was smart I could probably figure this out but I'm working this week and don't have time yet to look at this indepth. And somehow I suspect that no matter what I do, there's some secret thing that west host has to do to make it work so I just thought I would ask first. Thanks again for your kind attention.
Ray


I looked at the htaccess file for the old site --in fact I copied it --but there's nothing in it to allow this kind of action.

wildjokerdesign
04-04-2013, 08:20 AM
Well I did miss something before. It should be AddHandler and not SetHandler. SetHandler I think is what is causing the normal .html files to fail.

AddHandler cgi-script .cgi

I also think that the first directive should technically be this.

Options +ExecCGI +Includes


With all that said though this should not be needed at all. What you are trying to do should work out of the box I think. On the cPanel accounts I Apache handlers for both cgi-script and server-parsed are set up so the AddHandler should not be needed and accourding to the knowledge base http://kb.westhost.com/questions/142/Can+I+add+my+own+CGI+scripts%3F it should be set up to use the cgi-bin

Lucky
04-04-2013, 03:45 PM
I'll keep that in mind. I do have a ticket open on it but I was just trying to solve it myself. I think you're right that it should work out of the box but maybe there's something unique to this account --like some hosts make you rename file extensions, etc. I'll keep you posted.

Lucky
04-04-2013, 05:10 PM
Well I did miss something before. It should be AddHandler and not SetHandler. SetHandler I think is what is causing the normal .html files to fail.

AddHandler cgi-script .cgi

I also think that the first directive should technically be this.

Options +ExecCGI +Includes


With all that said though this should not be needed at all. What you are trying to do should work out of the box I think. On the cPanel accounts I Apache handlers for both cgi-script and server-parsed are set up so the AddHandler should not be needed and accourding to the knowledge base http://kb.westhost.com/questions/142/Can+I+add+my+own+CGI+scripts%3F it should be set up to use the cgi-bin

Yes, your code worked better. It does not prevent my html pages from working. However, now neither your version or the original two lines work or make the SSI appear. Something must have changed somewhere. Still troubleshooting...
the only error I get is " unable to include "/cgi-bin/rotate.cgi" in parsed file"

wildjokerdesign
04-05-2013, 07:06 AM
Well I know that Isaac was looking into the issue. Might be the admins are making some changes to things.

Try dropping the first forward slash in your path to the file to make it relative. "cgi-bin/rotateaftra.cgi". The documentation on that was a bit confusing but I think that technically that is what it should be. Oh and double and triple check spelling. Never know... I've spent days looking for an error only to realize I miss typed something. :)

Lucky
04-08-2013, 08:14 AM
Well I know that Isaac was looking into the issue. Might be the admins are making some changes to things.

Try dropping the first forward slash in your path to the file to make it relative. "cgi-bin/rotateaftra.cgi". The documentation on that was a bit confusing but I think that technically that is what it should be. Oh and double and triple check spelling. Never know... I've spent days looking for an error only to realize I miss typed something. :)

Oh, I know -it can be ANYTHING! Well, I found the problem. My path within the CGI script pointed to a wrong location for the other files it required. Instead of "/cgi-bin/xxx.xxx", it needed "xxx.xxx". Weird. But I'm just happy it works now.

wildjokerdesign
04-08-2013, 08:53 AM
Glad you sorted it out!