views:

107

answers:

3

All I want to do (initially) is the following:

<?php
phpinfo();
?>

I have two different web servers running. If I try to open the 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.

A: 

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.

Ignacio Vazquez-Abrams
just echoed the extra stuff (the two echoes), and exact same response from python.
mrsmoothie
That gets rid of the 500 error, sure enough. But I guess I will have to go over to Gentoo.org and do some more research. I can run only scripts in the cgi-bin. How do I call phpinfo() from a script?
mrsmoothie
A: 

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

coder
+1  A: 

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.

mrsmoothie
But this is not CGI. This is mod_php.
Ignacio Vazquez-Abrams
True. The CGI error was coming from the python twisted web server. Sorry to confuse you all. I just wanted to be able to render a php script within a *.php or *.html file. It didn't work with apache, so I tried opening with the python twisted web server. Thanks for the help, Ignacio.
mrsmoothie