cisco_s
Nov 21 2003, 01:35 AM
I've spent the past 6 hours trying to figure out why I'm getting "Premature end o f script header" errors on scripts I put into cgi-bin. I'm trying to install "MovableType" blogger software. I've found all the ideas in this forum. I've:
> made sure everything is chmod 755
> copied the older suexec over the suexec that the plesk update 6.0.1 installs
> restarted http many times
> tried simple cgi and pl scripts for testing (same errors)
> tried various combinations of permissions and ownerships
No matter what - ALWAYS "Premature end of script headers"
On other servers I've worked on I've never had problems with cgi-bin.
the ONLY thing that worked was deleting suexec from /usr/sbin/suexec (and copying it to /root). Scripts work fine now.
Since its working like that, should I leave it like this? Or have I opened up a gaping huge security hole?
:confused:
Squire
Nov 21 2003, 06:15 AM
umm....yeah, that's a pretty huge security hole you just opened. I'd change that one back right away.
Also, check the domain setup and make sure mod_perl is not enabled for the domain in question. Most scripts, MT included, are not written well enough to function with mod_perl enabled.
Squire
4PSA
Nov 21 2003, 02:04 PM
Have you checked the su_exec log file?
cisco_s
Nov 21 2003, 11:04 PM
QUOTE
Originally posted by Squire
Also, check the domain setup and make sure mod_perl is [B]not enabled for the domain in question.
I clicked it off, restarted httpd. Still get "Internal Server Error".
suexec_log has nothing. Well it has errors about "directory is writable" but that was from yesterday when I was testing different configurations. error_log for the site keeps saying "premature end of script headers". I give up. I'll have to find a non-cgi blogger.
Squire
Nov 22 2003, 07:23 AM
It'll end up being something simple Cisco. Seems like it always does. We just need to hit on what exactly is happening. Don't give up yet, you'll need CGI to work properly.
Double check to make 100% sure the scripts are being uploaded in ASCII mode. Why do I say that?
Used to be that the out-of-the-box ProFTP installation set the default transfer mode to Binary if none was sent by the FTP client.
Dunno if that is the same still or not, because I have a tweaked proftpd.conf file that I immediately overwrite the default one with when I upgrade a server. My tweaked version changes this default ProFTP setting, along with a few other things.
If you're not sure and want to tweak your /etc/proftpd.conf file, just pico -w into it and add the line:
DefaultTransferMode ascii
and save it. No need to restart anything. It'll take effect the next time an FTP connection is made.
Squire
Ales
Nov 23 2003, 01:01 PM
This could be an "end of line" character problem. Did you perhaps edit your script on a windows machine?
What you could do is try to (edit on the server!!!) change:
#!/usr/bin/perl
to
#!/usr/bin/perl -w
and than try executing it. Make sure you delete all the empty spaces at the end of the line. If it starts working, try switching it back to be without -w.... It might start working.
If it does start working, it should work with mod_perl enabled too.
cisco_s
Nov 24 2003, 02:05 PM
The files never set foot on a windows machine. I downloaded the tar directly to the server and untarred it there, and edited the files with vi through ssh. I gave up on MovableType and installed WordPress, a pure PHP and MySql blogger. Seems to work well, it'll just need a little hacking to add a couple features the client wants. Maybe in the future when I really need cgi I'll just pay a company to "fix it" for me.
ZoReN
Feb 23 2004, 05:10 PM
Having the exact same problem...
One thing though... I can't find suexec_log
I've checked /var/log/ and no luck...
4PSA
Feb 24 2004, 08:56 AM
Issue this command on your server and tell me what you get:
ls -la /usr/sbin/suexec
ZoReN
Feb 24 2004, 10:58 AM
[root@plesk root]# ls -la /usr/sbin/suexec
-r-s--x--- 1 root root 15744 Feb 23 17:35 /usr/sbin/suexec
CXNet
Feb 24 2004, 03:41 PM
I've had similar problems resulting in Internal Server Error.
I ran command and got:
[root@web1 root]# ls -la /usr/sbin/suexec
-r-s--x--- 2 root apache 16068 Feb 5 10:45 /usr/sbin/suexec
johnmd
Feb 24 2004, 04:09 PM
are these on plain boxes or on cpanel or pleask.
The reason I ask is I had to recompile suexec to change the doc root to /home
so everything underneath it will run
-D DOC_ROOT="/home"
that was on a plain redhat box.
Might help not sure if its related to your problem.
You could write a simple hello world perl script to test and see if it executes in your browser.
At least it would elimiate a buggy script from the equation.
eg
#!/usr/bin/perl
print "Content-type: text/htmlnn";
print "this is a testnn";
CXNet
Feb 24 2004, 04:16 PM
I'm using Plesk 7.
Yeah, I've tried basic scripts. Or, Hello Scripts. They work fine!
And, so does my 'problem' script on all other servers! :-)
This is in my error log:
[Tue Feb 24 15:43:27 2004] [error] [client 208.180.31.92] Premature end of script headers: samplemodify.pl
[Tue Feb 24 15:43:27 2004] [error] [client 208.180.31.92] failed to open log file /var/log/httpd/suexec_log
[Tue Feb 24 15:43:27 2004] [error] [client 208.180.31.92] fopen: Permission denied
ZoReN
Feb 24 2004, 04:18 PM
This is on a Plesk Box.
Thanks Johnmd,
I've tried this simple script and it still shows the same problem...

Is there a config file for suexec so I can check the settings of it?
This is what I get from error_log:
[Tue Feb 24 17:04:02 2004] [error] (13)Permission denied: exec of /usr/local/psa/home/vhosts/domain.com/cgi-bin/test.cgi failed
[Tue Feb 24 17:04:02 2004] [error] [client 216.232.161.36] Premature end of script headers: /usr/local/psa/home/vhosts/domain.com/cgi-bin/test.cgi
even if the permission is set to 777 and owner.group domain.psacln
TIA,
WiL
johnmd
Feb 24 2004, 04:28 PM
yes ssh into your box and do an suexec -v
this will print out the compile options for suexec,you didn't mention if this was a plain redhat or a cpanel box.
also
error] (13)Permission denied: exec
are the owners filenames chown'd and chmoded correctly!.
Don't think this is suxexec.
do an ls -al on the file you are trying to execute and check that the owner of the file is the same as the owner of the directory that your are in.and that it looks somethin like
-rwxr-xr-x 1 fileowner groupowner 1167 Aug 2 2003 test.pl
CXNet
Feb 24 2004, 04:44 PM
QUOTE
Originally posted by johnmd
yes ssh into your box and do an suexec -v
this will print out the compile options for suexec,you didn't mention if this was a plain redhat or a cpanel box.
also
error] (13)Permission denied: exec
are the owners filenames chown'd and chmoded correctly!.
Don't think this is suxexec.
do an ls -al on the file you are trying to execute and check that the owner of the file is the same as the owner of the directory that your are in.and that it looks somethin like
-rwxr-xr-x 1 fileowner groupowner 1167 Aug 2 2003 test.pl
We Both mentioned that we were using PLESK boxes.
I'm not sure what you mean in the above. Can you clarify...it's very broken...
4PSA
Feb 24 2004, 04:45 PM
Zonen, the problem is suexec:
-r-s--x--- 1 root root 15744 Feb 23 17:35 /usr/sbin/suexec
chown root:apache /usr/sbin/suexec and it will work.
ZoReN
Feb 24 2004, 04:49 PM
suexec -v
didn't produce an output... and I can't find an suexec_log
[root@plesk cgi-bin]# /usr/sbin/suexec -v
[root@plesk cgi-bin]#
The same script still doesn't work with the proper permission and ownership and group member...
[root@plesk cgi-bin]# ls -al test.cgi
-rwxrwxrwx 1 vickyain psacln 82 Feb 24 17:03 test.cgi
ZoReN
Feb 24 2004, 04:55 PM
Hi 4PSA,
I've changed the owner and group of suexec and still have the same problem... even restarted httpd after wards... still the same...
[root@plesk sbin]# ls -al /usr/sbin/suexec
-r-s--x--- 1 root apache 15744 Feb 23 17:35 /usr/sbin/suexec
CXNet
Feb 24 2004, 04:58 PM
No output on mine either.... crazy!
ZoReN
Feb 25 2004, 06:08 PM
I don't know what happened but MoveableType worked but the simple Hello World script doesn't...
Weird, Argh....
Ales
Feb 26 2004, 03:54 AM
Seems like you have permissions of the script set to 777
-rwxrwxrwx 1 vickyain psacln 82 Feb 24 17:03 test.cgi
Set them to 755 and it should work. Any script set to 777 is blocked by suexec. Also make sure your cgi-bin directory is not set to 777.
Veloce
Mar 2 2004, 10:04 AM
QUOTE
Originally posted by Squire
Double check to make 100% sure the scripts are being uploaded in ASCII mode.
son of a gun... that was the problem with my script too
Thanks man!
mOjO_420
Mar 7 2004, 03:43 PM
If any of you have updated apache since you installed plesk be sure you are using the psa-suexec binary and not the suexec apache installs. (or even if you havent i would double-check anyway)
check the file sizes if /usr/sbin/psa-suexec is not the same size file as /usr/sbin/suexec with the following:
CODE
# ls -al /usr/sbin/*suexec
my output looks like this:
CODE
[root@serverbob /]# dir /usr/sbin/*suexec
-r-s--x--x 1 root root 15452 Jul 23 2003 /usr/sbin/psa-suexec
-r-s--x--x 1 root root 15452 Dec 18 15:39 /usr/sbin/suexec
if yours are not the same size then do:
CODE
# cp /usr/sbin/suexec /usr/sbin/suexec.apache2.bak
# cp /usr/sbin/psa-suexec /usr/sbin/suexec
this is a real common problem for plesk users and should be in big bold letters in a FAQ somewhere.
if your script still doesnt work check /var/log/httpd/suexec_log you probably have a problem with the permissions of the script itself. the script should be chown'd to the ftp account that has access to that dir and must chmod 755'd or suexec spits out errors in the log.
kamihacker
Mar 7 2004, 04:27 PM
for those [still] looking for another blog software not based on cgi, try "wordpress"
I haven't used it widely, but it works pretty nice
regards
Dfire
Mar 9 2004, 04:49 PM
Have the EXACT same trouble. All the scripts work accept the main script for MovableType .. mt.cgi same premature end of headers error.
My suexec reads:
ls -la /usr/sbin/suexec
-r-s--x--- 2 root apache 15452 Oct 23 00:37 /usr/sbin/suexec
Got the permissions double checked, etc.. still nothin'
kino
Mar 15 2004, 11:13 AM
Thanks mOjO_420
I think that was the final thing that got it working -
Went through the list -
1) making sure the file was uploading in ASCII
2) chmod'ing the file itself and the cgi-bin to 755
3) changing ProFTP to default to ASCII uploads
4) changing the httpd.conf
5) adding a -w to the script header
6) taken off apache_asp and mod_perl from the domain, stopped the PSA, restarted the PSA.
7) copying over the old suexec !
(just thought someone might want the whole list!)
I was testing on perldiver
Thanks to everyone who has written about this over the forums. Has anyone told Plesk that their 'out of the box' server (v.6) does not run .cgi?!?
Thx,
Kino
jaredfine
Jun 29 2004, 08:50 AM
Same exact prob as CXNet and ZoReN. I did copy the psa suexec over the new apache one and that seems to have gotten most things back up, FormMail script for example works fine now, no errors. However still a very simple HelloWorld script is generating:
[Tue Jun 29 10:31:09 2004] [error] [client IP] Premature end of script headers: hello_world.pl
[Tue Jun 29 10:31:09 2004] [error] [client IP] failed to open log file /var/log/httpd/suexec_log
[Tue Jun 29 10:31:09 2004] [error] [client IP] fopen: Permission denied
Anyone have an idea of what I need to change?
UPDATE:
It seems it was just a matter of updating the suexec (which you should do if your running Plesk and RH and the suexec and psa-exec files don't match in /usr/sbin) and restarting apache:
cp /usr/sbin/suexec /usr/sbin/suexec.old
cp /usr/sbin/psa-suexec /usr/sbin/suexec
/etc/init.d/httpd restart
And as far as the simple hello_world script goes, it was created in windows so simply adding the -w switch to the #!/usr/bin/perl line.
Hope this helps anyone with the same problem.
mOjO_420
Jun 29 2004, 11:41 AM
i dunno about all that crazy stuff you guys tried with the ASCII mode transfers... i mean.. i can see that as a possibility for problems maybe but i've never ran into it. anyway... heres a really simple checklist.
1.) MOST IMPORTANTLY:
make sure that you do this part:
cp -p /usr/sbin/suexec /usr/sbin/suexec.old
cp -p /usr/sbin/psa-suexec /usr/sbin/suexec
i dont *think* the apache restart is necessary.
NOTE: you may skip this step if you do:
ls -al /usr/sbin/suexec*
and your suexec and psa-suexec are the exact same size (in other words its already been done)
NOTE: you will have to do this again after every apache update. if you use up2date you might want to exclude automatic apache updates.
2.) File permissions!
any scripts in that cgi-bin dir MUST be 755 (not 777) AND i highly reccomend that you make sure they are chown'd by the ftp user (because they get executed as that user) and the group should be psacln. the "ftp user" is whatever username you would use when FTPing into that site.
if you uploaded the script via ftp you shouldnt have to worry about ownership, but you may still need to chmod it. if you copied it or wrote it from the shell then you probably do need to correct the ownership. if you dont know how to see the ownership then get a decent FTP client like FileZilla
http://filezilla.sourceforge.net and set the view column to display the owner/groups (or just learn to use the shell).
Also stop using wordpad or notepad to create CGI's. Use (my favorite) Scite or Metapad. Both are free and have tons of options (i.e. can do Unix files) and Scite will colorize the code for you.
serverkiller
Feb 26 2006, 11:33 PM
Fwiw,
Just ran into this problem on a new plesk/rh box with cgi scripts.
This is a plesk reloaded job, today's configuration (2006).
All perl / cgi scripts invoked from the browser must have either -w (warnings) or -t (taint mode) enabled in the she-bang. eg: #!/usr/bin/perl -tw
Went nuts trying to find out why some scripts worked and others would just 500 on me and this was the one thing that fixed it. Additionally, it's obvious that the suexec files are being fixed at the config level so it's not a problem now:
[root@server]# dir -al /usr/sbin/suexec
-r-s--x--- 1 root apache 17160 Aug 24 2005
[root@server]# dir -al /usr/sbin/suexec.saved_by_psa
-r-s--x--- 1 root apache 10188 Sep 1 08:12 /usr/sbin/suexec.saved_by_psa
[root@server]# dir -al /usr/local/psa/suexec/psa-suexec
-r-s--x--- 1 root apache 17160 Aug 24 2005 /usr/local/psa/suexec/psa-suexec
Still get the suexec log error (when taint or warnings mode isn't enabled), but I'm guessing that it's probably mod perl that's trying to invoke the error and access the log, maybe it's not owned/operated by root/apache? Dunno.
Oh well.
Another thing, and this one took 8 hours to figure out, if you've got a generic perl script that needs to send mail out, and you've got a dummy domain name set in the qmail 'me' file, you'll pull your hair out until you change the domain in that file to one that actually exists in the server. (located: /var/qmail/control/me).
Actually there are a LOT of problems if you order a plesk box and you're going to transfer your first domain to it LATER. DON'T DO THIS UNLESS YOU'RE A PLESK expert! And I'm not and it is a total exercise in futility to get it going PROPERLY.
Lastly, there was an old how-to on ssleay.pm install I wrote back in 2002, it still applies. If you need or have a client that needs ssleay installed to communicate with authorize.net, then 1.05 is still the only one I've found that works. I think this is more related to the version of open-ssl that's installed on the server than anything else though.
ymmv.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.