How do I install/allow php to run on Yosemite? I've read a lot about doing stuff through terminal, but none of the 'tutorials' are thorough, they just tell me to do 'sudo....' I've tried it, and still, I cannot get php files to work (I'm making a website and I need a php file).

  • I assume you've used instructions like this then? Can you tell us exactly how far you've got and where you are stuck? Mar 27, 2015 at 0:41
  • Yes, exactly! I got to the part where I have to edit the httpd.conf file, and I deleted the '#' they talked about, and restarted apachectl. Yet it's still not working. I think I might have messed something with the httpd file, and now I'm trying to reset that as well, but cannot @AlistairMcMillan Mar 27, 2015 at 0:52
  • You can run apachectl configtest in the Terminal to tell you if the conf file is okay. Mar 27, 2015 at 0:55
  • I did that, and there are no errors in my httpd file anymore, but I still cannot access localhost, and my php code is not running still, even after uncommenting the "LoadModule php5" and restarting apache @AlistairMcMillan Mar 27, 2015 at 1:12
  • 1
    FWIW... 1. PHP is already installed under OS X 10.10. 2. Following the directions in Installing Apache, PHP, and MySQL on Mac OS X Yosemite (link posted by Alistair McMillan) for just editing the httpd.conf, creating the phpinfo.php file and restarting Apache I was able to bring up http://localhost/phpinfo.php page just fine. So the direction do work although I did not sudo su -, just used sudo in front of the various necessary commands. Mar 27, 2015 at 1:40

3 Answers 3


If you are not very familiar with the command line and config files (and it appears that you are not) then get Apple's Server app (US$20 at the app store). PHP then becomes a check-the-box setup option, as does local DNS (also essential).

The only common web-related app you will actually need to install via the command line is mysql. There is a package installer on Oracle's website.

  • I've installed Server, and enabled PHP and DNS, now I have to install MySQL before any php code will work? Mar 27, 2015 at 11:56
  • @Mahmud Assamaray, You should be able to test PHP is functioning without first installing MySQL, that is tests that do not require MySQL be installed! Read my comment to you in your OP. Mar 27, 2015 at 12:18

Or you could just use MAMP which is an installable and easily removable installation of Apache, MySQL and PHP entirely separate from that which is installed with and in the operating system.

I like it because it is simple and if I mess something up in my tinkering I just trash the MAMP folder and reinstall.

It is free (though they do offer a commercial, supported, edition) and works just as well as the components that come with Mac O/S.

I have no interest in the company, I've just used it quite a bit in the past. Developing websites and even hosting them.


To run PHP files, you need PHP interpreter (basically php command).

You can install PHP using Homebrew using the following Terminal command:

brew install php56

If you don't have Homebrew yet, install via:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then use Apache, php-fpm or php built-in server (e.g. php -S localhost:8888) to run the site.

Or to run standalone files, run them directly, e.g.

php file.php
  • Why php is installed on plain OSX? (Yes there are reasons but they need explaining here and for the OPs lack of knowledge how is this better)
    – mmmmmm
    Apr 11, 2016 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .