How to Enable PHP in Apache for Mac OS X Yosemite & Mavericks
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
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.
Great article, very simple and straight to the point.
By the way in MacOs Sierra 12.2 still working! :)
work like a charm!
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?
It doesn’t work. I only get a blank page when I follow these instructions.
Works to enable php for everyone but you, that means you’re doing it wrong.
Thank you so much! I was having this problem and trying to solve for hours… I did what you said and worked!!! Stoked!!!
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.
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.
Or… you can use InVisibles and do the same with an ordinary text editor. : )
Thanks for the description.
Sorry. I’m new with this PHP stuffs. Does this step same with using XAMPP?
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.