# PHP help please...



## buc99 (Nov 26, 2002)

I created a file called hello.php with the following contents:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo "Hello World<p>"; ?>
 </body>
</html>

I get an internal server error when I try to load this page. So I tailed my error_log and got the following:

[Tue Nov 26 13:31:29 2002] [error] (8)Exec format error: exec of /Library/WebServer/CGI-Executables/hello.php failed
[Tue Nov 26 13:31:29 2002] [error] [client 127.0.0.1] Premature end of script headers: /Library/WebServer/CGI-Executables/hello.php

I followed the howto on howto set up PHP/mysql.  My php module is loaded in apache. I changed the permissions of the file to 755. Any ideas what I'm doing wrong?

Thanks.
SA


----------



## anarchie (Nov 26, 2002)

PHP files aren't CGI executables.  Try putting them in /Library/Webserver/Documents.


----------



## buc99 (Nov 26, 2002)

That just prints out the file contents.

No php execution.

SA


----------



## buc99 (Nov 26, 2002)

I figured it out.

Looks like some typo on my end.

PHP is up and running.

Thanks.
SA


----------



## anarchie (Nov 26, 2002)

Looks like you didn't completely set up mod php. Do you have a line like this in your httpd.conf?

AddType application/x-httpd-php .php


----------



## MacLuv (Nov 26, 2002)




----------



## TommyWillB (Nov 26, 2002)

<?php echo "Hello World<p>"; php?>

not 

<?php echo "Hello World<p>"; ?>

Right?


----------



## MacLuv (Nov 26, 2002)




----------



## TommyWillB (Nov 26, 2002)

D'oh!


----------



## MacLuv (Nov 26, 2002)




----------



## buc99 (Nov 27, 2002)

I'm not sure why this caused such a big stink. But when I wrote the script in bbedit I did it as part of a new html document and used the default html headers from bbedit. I then saved it as a php file and the browser would do nothing bu t show the text. So I (ever so stupidly) thought maybe I need to change the permissions and make it executable. Duhh. That was not the problem still printing the text file in the browser. So I went back and just put the html/php code minus the bbedit into a new .php file created in vi.  This seemed to fix the issue now because the php script is printing correctly and I'm not seeing lines of code in my browser.

Does anyone know why this bbedit header caused this hiccup. It does not do this for normal html files and I figured it would not make a difference since php is embedded code in html. Maybe it should be saved as an html file? Will the php code still work then?

Thanks.
SA


----------



## RHITMacMan (Nov 28, 2002)

I think I had this problem at one time or another, a really really long time ago.  I think one of my problems was that the editor I was using was not saving the text files with Unix line ends.  Instead, it was using MacOS 9 style line endings.  So changing one of the settings in BBEdit to use Unix style line endings could help.  Vi should definitely by default use Unix line endings, where as BBEdit didn't for me by default from what I remember.


----------



## burntoutjoy (Dec 4, 2002)

> _Originally posted by TommyWillB _
> *<?php echo "Hello World<p>"; php?>
> 
> not
> ...



wrong - you were right first time!
but if you're going to do it all on one line, use_ either_

<?php
  echo "Hello World!";
?>

_or_ 

<?="Hello World!"?>

which does exactly the same thing, but is more readable for the one line thing.


----------

