Forum Moderators: coopster & phranque

Message Too Old, No Replies

Premature End of Script and Error 500

Error 500, Apache, Debian, Perl, Permissions, Premature End of Script

         

Paymaan

10:34 am on Oct 17, 2008 (gmt 0)

10+ Year Member



Hi there,

I need to use some specific hosting server for a project and I have to use one of my Perl scripts there (basically I use Perl for most of my codes), but there is a big issue with this. The web masters and admins seem they don't have enough knowledge to resolve the problems. the config is like this:

Apache/2.0.54 (Debian GNU/Linux) FrontPage/5.0.2.2635 mod_python/3.1.3 Python/2.3.5 PHP/4.3.10-16 mod_ssl/2.0.54 OpenSSL/0.9.7e mod_perl/1.999.21 Perl/v5.8.4

The control Panel is "Confixx", server is Debian Linux.

whenever I try to run a simple test on the cgi-bin directory so I get the perl to work first, something as simple as something like this:

----
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";
print "testing.. $ENV{'DOCUMENT_ROOT'}";
----

Every time I get the error saying "Premature End of Script x.cgi, Error 500" along some other text.

I don't have shell access to the server and no telnet access. I have tried every of solutions I have found on web, nothing have yet worked for me.

I know path to the perl, send mail exists and works, I have changed permissions to 755 and 777 without any luck yet, tried sending explicitly as ASCII, again no luck. tried several other simple test scripts, no results so far.

access log is not much descriptive, it contains only the error number and some other useless (for me) info.

So, please somebody give me some helps, hints, on how can I step by step try to resolve this problem.

Thanks a lot!
Paymaan.

rocknbil

2:33 pm on Oct 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have experienced the following a LOT. So much, in fact, on some servers I can duplicate it without failure.

PC plain text and Unix plain text have different end of line/return characters. On the right servers, if I save a script in PC format (NotePad) it will error every. single. time, with the same obscure error. However, if I save the file in Unix format, no problems.

This is one of the reasons I use HomeSite, which has the ability to set the output file format, PC or Unix. Try to open one of my scripts in NotePad and you get those awful square boxes without any formatting.

So look into that, I'm sure you tried removing the "use" line, that would be the only other thing I see. Adobe killed HomeSite in favor of Dreamweaver <rolls eyes> so you may not find it, but there are many editors that can save in Unix format, some of them free.

Paymaan

7:18 pm on Oct 17, 2008 (gmt 0)

10+ Year Member



Well, Actually I have tried these as well. I have used both notepad, and more than that, CuteFTP's editor. To make it 100% sure, I used the export feature of NoteTab to export text to Unix format. That works on every of my other websites.

I have removed the first line for test, and saved in Unix format, the same problem happens.

One question, is it possible that FTP server prevents ASCII downloads, even if the user sets the mode to ASCII?

Paymaan.

Paymaan

8:36 am on Oct 18, 2008 (gmt 0)

10+ Year Member



I checked with the admin, and tried to run the cgi scripts from shell prompt, fortunately they worked and out put some text on shell, so perl is working, ascii is not a problem, so somebody please help, what else can generate that error and what web configs need to be checked?!

Paymaan.

[edited by: Paymaan at 8:37 am (utc) on Oct. 18, 2008]

phranque

10:50 am on Oct 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



perhaps the server cannot get access to the directory containing the script.
what does the error log say?

Paymaan

12:49 pm on Oct 18, 2008 (gmt 0)

10+ Year Member



I have no telnet access to the server, the only log I can see is access log which just Gives the error 500, tried to use CGI Carp, it didn't change that log, where can I find the error log?

Paymaan

5:58 pm on Oct 19, 2008 (gmt 0)

10+ Year Member



Ok, I did several other things, I tried to work from an ubuntu computer to send the files, and it gave no different results, so everything with ASCII is wrong. I uploaded the same scripts to my other website and they all worked.

I also wrote a shell script (script.sh I mean) as a cgi and uploaded in the same directory and it didn't work either. So somebody please help me find where in the server and which configuration might be wrong, Just know that they are also using suExec on this server.

Paymaan.

[edited by: phranque at 3:16 am (utc) on Oct. 20, 2008]

Paymaan

8:14 am on Oct 23, 2008 (gmt 0)

10+ Year Member



ok nobody seems to have a solution to my problem after several days, so please somebody gives an answer on this to me:

Imagine somebody has installed the Debian Sarge, Perl and mod Perl along Confixx on a server (also python, php, ssl, and I know php works fine).

Now tell me if still CGI is disabled (all cgi possibly, not only perl), with a premature end of script error + a 500 internal server error, what steps do you take to find the problem?

How can I enable this, if I have root access? and what if I do not have root access?

Paymaan.

phranque

10:38 am on Oct 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the first thing i would do is look at the server error log.
anything else is rolling dice.
if you want my first roll, make sure your path to perl is correct.
for my second roll, i would look at the apache config to see if it is set up to run cgi.
but if you can do either of those, you can probably find the error log...

Paymaan

6:35 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



Thank you phranque, path to perl is correct because perl scripts are executed from shell, and show the output.

abot checking apache config, is this the same config I normally use to enable cgi in other linux OSes, like ubuntu and SuSE? But there when CGI is not enable I do not get a "Premature End of Script", just a Internal Server error.

Anyway, which log file should I ask root to copy for me? is there a directive he can give me direct access to my own error logs related to my own virtual host? how can he enable this?

Paymaan.

phranque

8:18 am on Oct 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the default location for the log files is /var/log/httpd.
yours may be in a subdirectory since it is a shared environment.
or it also could have been put in another directory, such as a subdireectory of /etc.
apache usually puts out 2 log files, one for access logging and one for error logging.
if you can't arrange access to both files, i would suggest changing host providers.

Paymaan

10:12 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Thanks Phranque,

I will ask the admin for the error file in the path you've mentioned, after weekend. I can see acceess log, but it doesn't say much about errors, so I have to check the error log.

Changing the host provider, unfortunatley is not an option, if it was, I had my own host provider which is one of the best I have used since 1999!

Another option, which might be a little expensive is to set up and put a dedicated server there with full access. What Linux type do you suggest, and what control panel (better to be free and open source), and other environment do you suggest? Is there any simple step by step guide somewhere in the forum telling how to set up a hosting?

Regards,
Paymaan.

phranque

10:45 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the Webmaster General forum Charter [webmasterworld.com] prohibits discussion about specific hosting providers.
access to the error log is such a basic requirement that you should see if you can get that from your current provider first.

Paymaan

7:51 am on Oct 25, 2008 (gmt 0)

10+ Year Member



No I don't mean I need you to introduce a hosting to me, I mean if I want to set up a server, which Linux do you suggest, Debian, Open SuSE, Ubuntu, which of those free versions are better, in general, according to your experience?

phranque

10:53 am on Oct 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



sorry i misunderstood your question.
i would go with netbsd.
i think your step by step guide is called LAMP, which stands for linux (or bsd or some proprietary unix), apache, mysql and perl/php/python.
but that is a topic for a new thread.

Paymaan

11:18 am on Oct 25, 2008 (gmt 0)

10+ Year Member



Ok, so what good you have seen in NetBSD over others?

phranque

11:56 am on Oct 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



my linux experience is limited to some early redhat distributions and another i can't remember the name of at the moment.
not really relevant today.
i've been doing unix systems for longer than i care to admit so i don't really need a control panel or any bells and whistles.
i just go in and get my hands dirty - like a command line and vi.
netbsd supports almost any platform you can imagine.
the default install is lean and mean and you can customize your system with network aware package management tools.
good security.
things work.

Paymaan

3:05 pm on Oct 25, 2008 (gmt 0)

10+ Year Member



ok, thank you so much for the hints!

Paymaan

3:23 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



Ok, I got access to my error log file, by asking the admin to add Errorlog directive to my Virtual Host settings in Apache.

Now still the error level is something it just gives the same basic "Premature end of scripts". I guess now I can ask admin to change the level of my error log, so what shoudl I put in the config (and where) so I can get detailed info on this error?

phranque

11:02 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



are you still using your simple test script from the original post with "use CGI::Carp qw(fatalsToBrowser);"?

Paymaan

4:21 am on Oct 28, 2008 (gmt 0)

10+ Year Member



Yes, I am using an script even simpler, just a content-type and another single print. I have tested this elsewhere and it works.

I also tried putting something in .htaccess to enable cgi, <directory> and Options ExecCGI, but it seems .htaccess is prevented from running those as I got errors for .htaccess.

Actually I went to the hosting center and worked with the admin to find a problem, he is now willing to help, and what I saw was that Confixx adds some includes to the Apache2 configs to build virtual hosts and those are very simple, so I guess I have to understand what to add to enabale everything missed.

phranque

6:53 am on Oct 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



so just to review, please post the exact script you are currently using and the current permissions of the script file.

and is there any other message in the error file related to this HTTP GET request besides the "Premature end of script headers:" or is there also a "Permission denied:" or "No such file or directory:" or any other error listed?

usually if the only error is "Premature end of script headers:" the script is running but ended without sending headers.

Paymaan

7:12 am on Oct 28, 2008 (gmt 0)

10+ Year Member



This is the most complex one I use:

---
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

use Config;
print "Content-type: text/html\n\n";
if ($Config{usethreads}) {
print "has thread support\n"
}
use Config qw(myconfig config_sh config_vars config_re);
print myconfig();
print config_sh();
print config_re();
config_vars(qw(osname archname));

----

Then as a sample, the error line is something like this:

[Tue Oct 28 08:27:17 2008] [error] [client [ip]] Premature end of script headers: test.pl

The permissions for the script is 755, and I have tried running the script both outside the cgi-bin and inside, the same happens.

phranque

7:29 am on Oct 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



have you tried naming the file test.cgi instead of test.pl?
i think i have seen an apache config directive that requires this...

Paymaan

8:00 am on Oct 28, 2008 (gmt 0)

10+ Year Member



I have tried both forms, test.cgi and test.pl do the same.

Paymaan

10:52 am on Nov 3, 2008 (gmt 0)

10+ Year Member



Ok, Thanks for everybody's help, although nobody could resolve the problem.

I finally managed to find an answer to the problem resolving it and here is the reason:

it seems suexec was preventing the scripts from being executed. I checked the suexec error log with admin and this line was there:

[date time]: uid: (1504/userid) gid: (1504/1504) cmd: test.pl
[date time]: command not in docroot (/home/www/userid/html/cgi-bin/test.pl)

So I asked the admin to remove the line in my virtual host config containing this:

suexec userid userid

which was the reason. I guess there are other methods like setting the correct id for this virtual host, but I am not familiar with them, and I don't need the suexec to control my cgi-bin, and my site doesn't hold sensitive data, so the current solution will do fine for the moment.

Paymaan.

phranque

11:45 am on Nov 3, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



thanks for reporting the resolution to this problem, paymaan!
hopefully next time someone with the suexec issue searches WebmasterWorld for "Premature End of Script" [google.com] they will see your solution.
i think my first response was close to home - just had the wrong error log...

i would suggest getting your entire virtual host configuration and making sure you understand every directive in there.

Paymaan

10:27 pm on Nov 3, 2008 (gmt 0)

10+ Year Member



Well I reported for the same reason because I searched a lot for the same problem everywhere and none of them was leading a "Premature end of script headers" to a suexec related error.

How I did find the resolution without having direct access to root was that first I went there to the admin and fixed the error log in my virtual host setting to some file "inside" my own hosting directory, so I could read it. Then later asked my admin to give me a copy of Apache.conf, Confixx.conf (and all realted configs) along my own Virtual Host config files.

I studied all of them, tried putting "AllowOverride All" inside of it so I could change things using my ".htaccess" file. Then when none gave an answere, as a last resort, I asked admin to disable suexec, and then I found this suexec error log telling the other error, and I removed the line containing suexec command inside my own virtual host config.

he other part of site may still have the problem, but now I know what is the source of problem.

It took a lot of time with the no-access way I had, but at least we got some results.

Thanks,
Paymaan.