Running PHP as a CGI: Apache premature end of script headers
The_Corinthian
Joined: 2003-08-26
Posts: 11 |
Posted: Thu, 2003-08-28 19:48 |
Hello everyone, Anyway, when I try to access the gallery page, I get a 500 internal server error. Over and over, the Apache server log reports the following: All that this tells me is that my .htaccess file is referring the server to the appropriate cgi script, but that it isn't working. PHPinfo tells me that the server is running i686, so I uploaded the intel php-cgi file in ASCII mode. Then I CHMODed it to be executeable. I did all unpacking and CHMODing from the shell; the files were uploaded (manually in the proper mode) from CuteFTP. So what's wrong? The server is running Apache v.1.3.22. URL to the gallery is www.thoughtemporium.org/php-cgi/gallery/ Thanks in advance for your help. |
|
Posts: 524
copy the phpinfo.php from the gallery setup directory to your webroot and call it from your browser and see if it will run
Posts: 11
www.thoughtemporium.org/phpinfo.php
Runs fine. But the .htaccess file that refers the server to the cgi script is in the php-cgi directory, not the webroot, so the webserver is probably executing the phpinfo.php file with the built-in php program.
Posts: 524
add this to an .htaccess file in your webroot
AddType application/x-httpd-phpcgi .php
Action application/x-httpd-phpcgi /cgi-bin/php.cgi
and see if it changes
Posts: 11
Thanks for the suggestion. Unfortunately, I am getting the same error message (generated more now that I've tried again):
[Fri Aug 29 04:18:30 2003] [error] [client 24.223.154.216] Premature end of script headers: /home/virtual/site10/fst/var/www/cgi-bin/php.cgi
Also, the SERVER root is not writeable from my account. The HTML root is writeable. I simply replaced the lines AddType application/cgi-php php
Action application/cgi-php /cgi-bin/php.cgi with the two lines you recommended above in the php-cgi directory within the HTML root.
Posts: 524
the php.cgi binary should have been uploaded in binary form NOT ascii to your cgi-bin directory and after its uploaded make t executable like this
chmod a+x php.cgi
then if you add an .htaccess to your webroot with this in it
AddType application/x-httpd-phpcgi .php
Action application/x-httpd-phpcgi /cgi-bin/php.cgi
you should be able to run a php script using the cgi binary from anywhere in your webtree
Posts: 11
Hold on...
Posts: 11
I did exactly as you said, and STILL I get the premature end of script headers error every time I try to access the gallery page. This leads me to believe that the .htaccess file is redirecting apache to the php.cgi file properly, but the script itself is to blame. I uploaded it in binary, and I CHMODded it also: could it be the wrong script? I'm using the linux-2.4-intel script, and if you look at www.thoughtemporium.org/phpinfo.php, it would see that this is the appropriate script to use. Ack!
Posts: 524
usually Premature end of script headers are from
1. Permission errors
2. a CR/LF problem
or
3. a shebang problem(in this case we dont need this one)
so im leaning more toward permission errors
I do not have much knowledge of running php as cgi and am running out of ideas, I am not sure whether running php as a cgi the php files need to be executable as well?... ie chmod 755, I would think not, but am not sure on that you could try the phpinfo as 755 instead of 644 and see if the problem still persists and we may also have to remove the php handle first
like so
RemoveHandler .php
AddType application/x-httpd-phpcgi .php
Action application/x-httpd-phpcgi /cgi-bin/php.cgi
Posts: 11
Just to be safe, I set all the php scripts and directories within gallery to 777 before trying all of this.
I've been snooping around on google, and it seems that 'premature end of script headers' errors are quite common, so there are many possible reasons I could be recieving one. I guess I'll just let the thread stew a while and see if anyone else has any ideas. Thanks for all your help and suggestions: your troubleshooting has hopefully brought me one step closer to a solution.
If you want to log in on the server and see what you can do, that's cool too.
Peace.
P.S. As per the FAQ page, I have always been removing the handling first.
Posts: 12
It looks like you got it to work -- how did you manage it? I'm getting 500's, but not on the php-cgi itself, but on the phpinfo script (which is from the gallery setup dir).
Any ideas?
-Paul
Posts: 1
I was hitting this "premature end of script" error too. Turned out it was a conflict with cgi...cgi was trying to execute my php scripts, which didn't work. I commented out this stuff from my apache conf and it started working:
ScriptAlias /cgi-bin/ /usr/rickshaw/offsites/wiki/
SetHandler cgi-script
Options +ExecCGI
-Travis