Running PHP as a CGI under apache - problems.

Posted on 2005-03-09
Medium Priority
Last Modified: 2013-11-18
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.
Question by:jbwasted
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 51

Expert Comment

ID: 13499302
> 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

try to copy php to cgi-bin instead symlinking

Author Comment

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

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


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


Author Comment

ID: 13499452
edit- Not only is the user the owner, but they have proper access.
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

LVL 51

Expert Comment

ID: 13499515
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.

Author Comment

ID: 13499921
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.

Expert Comment

ID: 13582816
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?

Accepted Solution

modulo earned 0 total points
ID: 13816864
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question