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

Sep 10, 2012 - 6 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/libphp5.so

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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

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

6 Comments

» Comments RSS Feed

  1. 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.

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

  3. Tice says:

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

    http://blog.tice.de/index.php?rubrik=software&content=invisibles_engl

    Thanks for the description.

  4. 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.

  5. 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.

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

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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