How to Enable PHP in Apache for Mac OS X Yosemite & Mavericks

Sep 10, 2012 - 12 Comments

Enable PHP in Mac OS X

OS X Mavericks comes with PHP 5.4.30, and OS X Mountain Lion ships with PHP 5.3.13 preinstalled, though if you start the built-in Apache server, you will find PHP isn’t enabled by default. Changing this is easy, and if you’re a web developer and want PHP running on your local Mac with OS X 10.8 or later, follow along to have it working in no time.

Launch Terminal and enter the following command, using the administrator password when requested:

sudo nano /etc/apache2/httpd.conf

Now hit Control+W to use the search feature of nano, and type in “php”

Locate the following line and remove the comment (#) from the beginning:

LoadModule php5_module libexec/apache2/

Enable PHP5 in OS X

Now hit Control+O to save the changes, followed by Control+X to quit out of nano.

Back at the command prompt, you’ll want to restart the Apache server for the php module to load. This is done with the following command, or you can toggle the on/off switch in the 3rd party WebSharing panel:

sudo apachectl restart

Apache quickly restarts and PHP will be enabled.

You can verify this by throwing any php file into the ~/Sites/ directory and loading localhost/~user/file.php into a web browser, or you use phpinfo() to check the existing php configuration by placing the following into any file with a php extension:

<?php phpinfo(); ?>

Save that file into the user ~/Sites/ directory and load it into a web browser.

If you want to make any changes to PHP configuration, use the following command to make a copy of the default php.ini file:

cp /private/etc/php.ini.default /private/etc/php.ini

Make adjustments to the copied php.ini file in /etc/ or /private/etc/ as necessary, leaving the original .default file intact. As usual, any major changes to php.ini will need to be followed by another Apache restart to take affect.


Related articles:

Posted by: William Pearson in Command Line, Development, Mac OS, Tips & Tricks


» Comments RSS Feed

  1. Miguel says:

    Thanks Bro!!!!

  2. Otsen says:

    Great article, very simple and straight to the point.

    By the way in MacOs Sierra 12.2 still working! :)

  3. shellbye says:

    work like a charm!

  4. Jane says:

    Why won’t the # delete?

    Apache is on
    I have the file and found the string
    But darnit, the darn # will NOT delete!

    What am I doing wrong?

  5. Brian says:

    It doesn’t work. I only get a blank page when I follow these instructions.

  6. jackie says:

    Thank you so much! I was having this problem and trying to solve for hours… I did what you said and worked!!! Stoked!!!

  7. Don Brandt says:

    Stick with MAMP or MAMP PRO. This is for Mac OX only. Try WAMP Server for Windows side. Much simpler and MAMP & WAMP Server are free. MAMP PRO will cost you a minimal fee. There is also XAMPP which will work on either Mac or Windows and is open source as well. All are easier to set up if you do not want to mess with the Terminal side of things.

  8. Ewit Doewin says:

    I still think MAMP is the best solution because there’s no configuration and you can just open it to host a server, close it to stop. Much easier, hassle free, and it has MySQL too.

  9. Tice says:

    Or… you can use InVisibles and do the same with an ordinary text editor. : )

    Thanks for the description.

  10. Sorry. I’m new with this PHP stuffs. Does this step same with using XAMPP?

  11. Justin says:

    It’d be nice if there was a simple control panel to control all of this, just flip on web sharing, flip on php, etc.

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site