Setting up PHP & MySQL on OS X Mavericks – Rob Allen's DevNotes


: 8

With OS X 10.9 Mavericks, Apple chose to ship PHP 5.4.17. This is how to set it up from a clean install of Mavericks.

Note: If you don't want to use the built-in PHP or want to use version 5.5, then these are some alternatives:

Let's go!


Ensure that the following directories exist and have the right permissions:


  1. Download the "x86, 64bit" DMG version of MySQL 5.6.x for OS X 10.7 from and install the pkg, the startup item and the pref pane.
  2. Open the pref pane and start the MySQL Server.
  3. Update the path by editing ~/.bash_profile and add:

    at top of file.
  4. 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.
  5. Now ensure that the mysql.sock file can be found by PHP:
    1. Ensure that MySQL is running
    2. sudo mkdir /var/mysql
    3. sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock


Apple have removed the "Web Sharing" feature from System Preferences, but Apache is still installed. We just have to use the command line now to start and stop it.

  1. cd /etc/apache2
  2. Give write permission the config file to root: sudo chmod u+w httpd.conf
  3. Edit /etc/apache2/httpd.conf
    1. Find #LoadModule php5_module libexec/apache2/ and remove the leading #
    2. Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
  4. Restart Apache: sudo apachectl restart
  5. Give yourself permissions to the /Library/WebServer/Documents/ folder using the terminal commands:
    1. sudo chgrp staff /Library/WebServer/Documents
    2. sudo chmod g+rws /Library/WebServer/Documents
    3. sudo chmod g+rw /Library/WebServer/Documents/*
  6. Open Finder and navigate to /Library/WebServer/Documents/ using shift+cmd+g
  7. Create a new folder called "orig" and place all files currently in the Documents folder into it.
  8. Create a new file called info.php with <?php phpinfo(); inside it.
  9. Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.13 at the time of writing).
  10. Ensure that Apache will start after a reboot:
    sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist


  1. cd /etc
  2. sudo cp php.ini.default php.ini
  3. sudo chmod ug+w php.ini
  4. sudo chgrp staff php.ini
  5. Edit php.ini and change settings appropriately.
    At a minimum, you should change:


Can't have a PHP development environment without xdebug! Fortunately, Mavericks ships with it ready to enable:

  1. Edit /etc/php.ini and add this line to the end:
  2. If you want to configure your xdebug settings, then add an [xdebug] section. I like these settings (use with caution…):
  3. Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.


Install Composer into /usr/local/bin:

  1. cd /usr/local/bin
  2. curl -sS | php
  3. mv composer.phar composer


We need PEAR! For some reason, it's not set up ready to on Mavericks, but the install phar file is here, so we just need to run it.

  1. cd /usr/lib/php
  2. sudo php install-pear-nozlib.phar
  3. Edit/etc/php.ini and find the line: ;include_path = ".:/php/includes" and change it to:
    include_path = ".:/usr/lib/php/pear"
  4. sudo pear channel-update
  5. sudo pecl channel-update
  6. sudo pear upgrade-all
  7. sudo pear config-set auto_discover 1

PHPUnit and friends

I assume that everyone needs these…

  1. Edit ~/.bash_profile and add

    and now restart Terminal
  2. composer global require 'phpunit/phpunit=3.7.*'
  3. composer global require 'phpmd/phpmd=1.*'
  4. composer global require 'squizlabs/php_codesniffer=1.*'

You can update these tools in the future using composer global update

Compiling extensions

To compile extensions, you need the Xcode command line tools and autoconf.

  1. Install the command line tools: xcode-select --install and press the Install button.
  2. Compile and install autoconf:
    1. Install Homebrew:
    2. brew install autoconf

    or, manually compile and install autoconf from source.

Intl extension

If you need Locale:

  1. brew install icu4c
  2. sudo pecl install intl
    The path to the ICU libraries and headers is: /usr/local/opt/icu4c/
  3. Edit /etc/php.ini and add to the end.

Mcrypt extension

Follow the details in Plugging mcrypt into PHP, on Mac OS X Mavericks 10.9 by Michale Gracie. In summary:

  1. Download libmcrypt-2.5.8 from sourceforge
  2. Download the correct PHP source code from here. At the time of writing you need version 5.4.17.
  3. Extract the libmcrypt and PHP source code into ~/Desktop/src.
  4. Compile and install libmcrypt. Type these lines into the Terminal:
    1. cd ~/Desktop/src/libmcrypt-2.5.8
    2. MACOSX_DEPLOYMENT_TARGET=10.9 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
    3. make -j6
    4. sudo make install
  5. Compile and install the mcrypt PHP extension. Type these lines into the Terminal :
    1. cd ~/Desktop/src/php-5.4.17/ext/mcrypt
    2. phpize
    3. MACOSX_DEPLOYMENT_TARGET=10.9 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/usr/bin/php-config
    4. make -j6
    5. sudo make install
    6. Add to the end of /etc/php.ini using your favourite text editor
    7. Restart Apache using sudo apachectl restart
    8. Open up the info.php file and check that crypt is installed
    9. Delete the src folder from the Desktop


A couple of projects I work on use the PECL OAuth component:

  1. Download the latest PCRE source code from to your Downloads folder and uncompress it
  2. cd ~/Downloads/pcre-*
  3. ./configure
  4. sudo cp pcre.h /usr/include/
  5. Remove the pcre folder and tgz file on your Downloads folder as you don't need it any more
  6. sudo pecl install oauth
  7. Edit/etc/php.ini add these lines to the end of the file:
  8. Restart apache: sudo apachectl restart and check in the phpinfo that OAuth is now loaded.

It all works on this machine, anyway :)