The so far best tutorial I found on this which worked is by san bei ji. PHP is preinstalled but needs to be activated. To do so I recommend you have a suitable texteditor such as BBedit (minimum is version 6.5) although using the preinstalled pico also works. Go to utilities and open the terminal. You will see this print:

Last login: Mon May 23 19:56:17 on ttyp1
Welcome to Darwin!
ramp-1-22:~ yourusername$ 

After the $ sign type in:

sudo bbedit /etc/httpd/httpd.conf

and return. You will then be asked for your password. Return and then BBedit will open with the file. Using the search option search for php4. You will come to this line:

#LoadModule php4_module        libexec/httpd/libphp4.so

Remove the comment symbol # and search for php4 again. You will come to this line:

#AddModule mod_php4.c

Again remove the # symbol. Now search for

<IfModule mod_dir.c>

Replace

DirectoryIndex index.html

with

DirectoryIndex index.html index.htm index.php

and you are done. Save your changes and exit the terminal. If you are not sure that you have done the right thing, do not save and start allover again.

Before you test open system preferences and turn on web sharing as shown in the figure. Click on the two icons personal web sharing and personal

system preferences

To test if it works create a php file like this for example.

<?
echo(Date("l F d, Y")); 
?>

Now open your browser and type in the url:

http://127.0.0.1/~yourusername/example.php

You should see the present date print. And that's it. If you are not using personal web sharing all the time turn it off after you are done to reduce the vulnerability from outside to your computer.