Why doesnt my php script work
All I want to do (initially) is the following:
<?php
phpinfo();
?>
I have two different web servers running. If I try to open th开发者_StackOverflowe above in firefox, Under any filename, with the :80 port from apache, it merely echoes the above.
If I try to open the above, as any filename, from a python twisted web server on port :8888, I get a http 500 error (CGI Script Error
Premature end of script headers.)!
I am running Gentoo linux. I have installed and re-installed cgi different ways. Anything other file, not using CGI, is served up as expected with both web servers.
And the winner is:
<IfDefine PHP5>
# Load the module first
<IfModule !mod_php5.c>
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
AddHandler php5-script html
AddType text/html php
</IfModule>
# Set it to handle the files
<FilesMatch "\.ph(p5?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
DirectoryIndex index.php index.phtml
I don't really know what I am doing yet. All I know is I achieved the desired effect: any *.php or *.html file in my root htdocs directory will correctly render php SCRIPTS. I found a lot of confusion in web posttings about what this entails. My php scripts start with <?
and end with ?>
It was not necessary to write <?php
, nor is it necessary to write out any http headers in a *.php file.
you need not run the php as a cgi-bin. just put the file under htdocs folder.
make sure you loaded mod_php5 in the httpd.conf using LoadModule
and restart the server -> apachectl restart
it will work out of the box
You need to output the headers for CGI first:
<?php
echo "Content-type: text/html\n";
echo "\n";
phpinfo();
?>
Refer to the CGI documentation for more info.
EDIT:
Under httpd, you need to put the script in cgi-bin/
and access it via there, e.g. http://example.com/cgi-bin/phpinfo.php
.
精彩评论