Enabling Apache and PHP on Mac OS X (Lion)

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! :)

David Barreda

Engineering student, I like to enjoy my free time playing videogames and playing guitar, I love server administration. I enjoy testing different OS, but my best is on Linux and later OS X, and I'm not an stupid *BSD and Windows user, just im rusty. I also like reading books, listening music, traveling, and as you can see at this site, help people with problems that I can solve, enjoy. I'm also looking for an online job on UNIX system administration, so if you know about one, just comment here! ;)

More Posts - Website - Twitter - Facebook - Google Plus - YouTube

2 thoughts on “Enabling Apache and PHP on Mac OS X (Lion)