PHP scripts problem!

Hi,
I've configured a server with Debian Etch 4.0. I followed these instructions:

Install and Configure Apache2 with PHP5 and SSL Support in Debian Etch -- Debian Admin

But when I try to launch a php script with phpinfo() in my browser, It showed me the download manager window.(i.e. wanna to download the script instead of executing it)
For example:

http://localhost/test.php

Another thing is when I want to launch it from a public_html of user (I mean:

http://localhost/~someuser/test.php

It shows me this error:
Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
Premature end of script headers: test.php

If you think this is a server error, please contact the webmaster.
Error 500

Can anyone help me?

Your test.php file should have only the following:

<?php phpinfo(); ?>

Some sites will show this with spaces after and before the "<" and ">", but PHP will trip on those spaces. It's happened to me before.

My file in the /var/www was incorrect. But when I changed it as you said, It is behaved as my virtual host. (The virtual host's file content was correct before). It showed this error again for both cases:
Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
Premature end of script headers: test.php

If you think this is a server error, please contact the webmaster.
Error 500

I found that, this error is related to suphp module. When I disabled it with this command:

a2dismod suphp

every things works perfectly. I checked this suPHP - FAQ, there was something helpful:
Why do my scripts not work and why do I get an "Premature end of script headers" in the error_log?
You probably have installed the CLI version of PHP, but you need the CGI version. Copy the file /build/path/sapi/cgi/php to /where/ever/you/have/installed/bin/php to use the CGI version.
But I don't know what am I copying exactly!

Excellent! I'm glad you found a solution. Thanks for the info about it too.

As I said, I don't know, what files and where can I copy my files?

Check the "php" executable being used. You can run "php -v" on the command line. On my Debian system, it displays

cbkihong@cbkihong:~$ php -v
PHP 5.1.4 (cgi) (built: Jun  4 2006 00:37:25)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

which shows the CGI version is used. On another server of mine it shows the CLI version:

admin@np64gw:~$ php -v
PHP 5.2.1 (cli) (built: Feb  9 2007 23:01:18)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

The CGI version differs from the CLI version in that the CGI version will send certain required HTTP response headers, but the CLI version will not. For instance,

cbkihong@cbkihong:~$ php
<? echo "a" ?>
< HIT CTRL-D HERE >
X-Powered-By: PHP/5.1.4
Content-type: text/html

a

The version installed on a Web server should be a CGI version one instead of the CLI version. For Debian, the 'php5-cgi' is likely the package you should install.

It helps!!
As i am new to Debian and also soon i have to configure apache and PHP; both to work with hand-in-hand with our software.

-ilan

This is my result:

PHP 5.2.0-8+etch9 (cli) (built: Dec 29 2007 03:30:27)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

But either I'm uninstalling php5-cli or not, the suphp didn't work. (BTW: I've installed php5-chi before)

Also, I replaced php binary file with php5-cgi, but nothing changed.

I found the problem. We must configure suPHP in /etc/suphp/suphp.conf with proper configuration. Thanks to everyone :b: