1. Enabling Apache
By first, you will open the menu, then open System Preferences -> Sharing and enable Web Sharing, customize the settings if you want to, after this you should get the default Apache index on http://localhost with “It’s working!”. Done, you got Apache working, but still no PHP.
2. Creating phpinfo
Open the terminal and write
cd Sites ; echo "<?php phpinfo() ?>" >> phpinfo.php
Save it and close the document, then try to open http://localhost/~yourusername/phpinfo.php and see what you just wrote on the document since Apache still doesn’t have PHP plugin enabled.
3. Enabling PHP
For the sake of simpleness, Apple shipped OS X with PHP (as with Apache), now you just have to enable it. Open the terminal and write
sudo nano /etc/apache2/httpd.conf
Then look for this line:
#LoadModule php5_module libexec/apache2/libphp5.so
and remove the hash symbol and save the document, then restart Apache with
sudo /usr/bin/apachectl restart
Refresh http://localhost/~yourusername/phpinfo.php and enjoy!