Link to home
Start Free TrialLog in
Avatar of jbwasted
jbwasted

asked on

Running PHP as a CGI under apache - problems.

Hopefully this is thebest place to ask..

I'm trying to run PHP as a cgi under apache, I have takent he following steps:

create a softlink from /usr/bin/php to the user cgi-bin dir.

in .htaccess in the htdocs dir, i put:
Action php-suid /cgi-bin/php
AddHandler php-suid .sphp

Then I create a very simple php file in the same htdocs dir, just echos a single line.   Im sure it executes properly since I can run "php test.sphp" and it works fine.

So now, when I try to browse here, I get http error 500 and in error_log i get:
"....Premature end of script headers: php"


One note - cgi's are being run suexec, (which is why I am going through this all to begin with).

From what I've read, this should be working.. Any ideas anyone?
All help appreciated.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

> cgi's are being run suexec,
does the su'ed user have read permissions on the directory and the file?

what does
  php -f your.php && echo ok
print?

try to copy php to cgi-bin instead symlinking
Avatar of jbwasted
jbwasted

ASKER

Yep su'd user is the owner of directory and file.

pf -f... does :
Content-type: text/html

test!
ok


Okay, I tried copying php instead of linking, and that is weird, its like its trying to interpret the php binary.

No http errors wtih that, but php gives me this error:

Warning: Unexpected character in input: '' (ASCII=8) state=1 in /var/www/html/user_cgi/cmstest/php on line 942

Warning: Unexpected character in input: '' (ASCII=7) state=1 in /var/www/html/user_cgi/cmstest/php on line 942

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /var/www/html/user_cgi/cmstest/php on line 942

Thanks
edit- Not only is the user the owner, but they have proper access.
AFAIK apache's suEXEC does not allow symlinks, also the owner of the file must be the same as the su'd user.
I'm not shure where seEXEC searches the binary, think that's your problem.
Hmmmm Looks like a bug in php. http://bugs.php.net/bug.php?id=7641

I guess I'll compile a new version and see if that works.
What file editopr did you use to write the php script?

Looks like a symbol that word on microsoft windows would put into a file. Did you use some word editor to write the script?
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial