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
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!
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.