Setting up PHP & MySQL on OS X Yosemite


Homebrew is a package manager for OS X. Install it, as we’ll need it later:

You’ll also need the Xcode command line tools – at least version 6.1. Xcode is available on the Mac App Store as a free download. Don’t forget to start up Xcode at least once after initial installation.

Initially and after every major OS X upgrade, you might need to reinstall the Xcode command line tools and accept the license aggreement:

Also, don’t forget to create this missing symlink after upgrading to a new major OSX version:

Once Homebrew is set up and you want to upgrade outdated packages, run:

Remember to also run brew update && brew upgrade after upgrading to a new major OS X version.

List all installed packages:

You should never be required to run brew as root using sudo!


Apple ships PHP 5.5.14 with OS X Yosemite but we’re not going to use it and install the latest PHP 5.6 instead via Homebrew.

Tap homebrew/homebrew-php and all its dependencies (homebrew/homebrew-binary actually is no dependency but we might need it for binary PHP extensions):

Install PHP 5.6:

Install some PHP extensions:

Edit /usr/local/etc/php/5.6/php.ini and change settings appropriately. At a minimum, you should change:

We don’t need to restart Apache after any modifications in php.ini as we are going to run PHP as CGI.


As a PHP developer for sure you are going to use Composer! We are not going to install it directly in /usr/local/bin as this directory is write-protected for the regular system user and we don’t ever want to run Composer with sudo. Install it somewhere else and simply symlink it into /usr/local/bin:

Upgrading Composer is terribly easy and does not require superuser rights:


Download the „Mac OS X 10.9 (x86, 64-bit), DMG Archive“ from and install the following packages:

  • mysql-5.6.xx-osx10.9-x86_64.pkg
  • MySQLStartupItem.pkg
  • MySQL.prefPane

Then, open the pref pane and start the MySQL Server.

Update the path by editing /etc/bashrc (or ~/.bash_profile) and add:

at top of file.

Set up MySQL root password:

Clear the history file by typing history -c so that {new-password} isn’t in plain text on the disk!


OS X Yosemite (10.10) ships with Apache 2.4.9:

This is great – no need for any other Apache installation! We just have to use the command line to start and stop it:

Main Apache configuration in /etc/apache2/httpd.conf:

  • enable some modules (remove the leading # from these lines)
  • change the default user Apache is running as to your system user (like this you don’t run into any permission trouble in your own projects)
  • include /etc/apache2/extra/httpd-vhosts.conf virtualhost configuration (see below)
  • set some environment variables

Configure PHP as CGI in /etc/apache2/other/php5.conf:

Comment out the examples in /etc/apache2/extra/httpd-vhosts.conf and add the following lines:

You may then add all your VirtualHosts at the bottom of this file, e.g.:

Now, add the project’s hostname to /etc/hosts:

Flush the local DNS cache after every modification in /etc/hosts:

Create a phpinfo.php for testing:

Finally, test configuration and restart Apache:


One Response

  1. Lucas Vieira
    Dez 15, 2014 - 09:19 PM

    They changed the curl command to:

    ruby -e „$(curl -fsSL“

Leave a Comment