Install PHP and Mysql on OSX Mountain Lion

December 19th, 2012

Warning: This post is 12 years old. Some of this information may be out of date.

I usually develop on an Ubuntu VM running in VirtualBox but have needed to install PHP and MySQL on OSX Mountain Lion on the MacBook Pro. Here's a Github Gist from Aaron Brady with details on how to do it.

Install Xcode, Command Line Tools, Xquartz (on 10.8)

In a terminal (probably best to do one thing at a time):

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54 --with-mysql 
chmod -R ug+w /usr/local/Cellar/php54/5.4.7/lib/php
pear config-set php_ini /usr/local/etc/php/5.4/php.ini
PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"
cat >> /etc/apache2/httpd.conf < < EOF
LoadModule php5_module    /usr/local/Cellar/php54/5.4.7/libexec/apache2/libphp5.so
EOF
brew install php54-mcrypt
brew install php54-apc
brew install php54-xdebug
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.27/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl start homebrew.mxcl.mysql
cat >> ~/.profile < < EOF
PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"
EOF