Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hodadgists/7140316 to your computer and use it in GitHub Desktop.
Save hodadgists/7140316 to your computer and use it in GitHub Desktop.

Install MAMP stack on Mountain Lion using MacPorts

NOTE: I keep most of my Apache/PHP/MySQL configuration stuff in a local Git repository so I can track changes and I symlink to those from where they should be so you will see commands such as sudo ln -s ~/Documents/configs/PHP/fat-tony.local.php55.ini /opt/local/etc/php55/php.ini. If you don’t have a similar setup, just copy your configuration files to where they need to be.

ALSO: I like to prepend some of the commands with time just for curiosity’s sake to see how long it takes.

Turn off the built-in Apache

Go to System Preferences -> Sharing and uncheck the Personal Web sharing. You will never turn Apache on/off here again.

Install Xcode via Mac App Store

macappstore://itunes.apple.com/app/xcode/id497799835?mt=12

Install Xcode Command Line Tools

Find the latest version in the Mac Dev Center. (You must have a free Apple Developer account.)

Agree to Xcode license

Either launch Xcode via GUI or run xcodebuild -license

Install MacPorts

Use the Mac OS X Package (.pkg) Installer.

The installer will prepend your $PATH with the necessary /opt/local/bin:/opt/local/sbin:

Make sure MacPorts knows the path for Xcode

As of Xcode 4.3 you need to make sure Xcode knows where to look.

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

Make sure everything is up to date before installing any ports

sudo /opt/local/bin/port -v selfupdate

Install cURL and SSL

time sudo port install curl +ssl

Install PHP and APACHE 2

For Development (Includes Xdebug):

time sudo port install php55 +apache2 php55-apache2handler php55-curl php55-exif php55-ftp php55-gd php55-geoip php55-gettext php55-http php55-iconv php55-imagick php55-imap php55-ldap php55-mailparse php55-mbstring php55-mcrypt php55-mysql php55-openssl php55-pdflib php55-pear php55-posix php55-soap php55-sockets php55-solr php55-ssh2 php55-sqlite php55-xdebug php55-xmlrpc php55-xsl php55-zip

For Production (No Xdebug):

time sudo port install php55 +apache2 php55-apache2handler php55-curl php55-exif php55-ftp php55-gd php55-geoip php55-gettext php55-http php55-iconv php55-imagick php55-imap php55-ldap php55-mailparse php55-mbstring php55-mcrypt php55-mysql php55-openssl php55-pdflib php55-pear php55-posix php55-soap php55-sockets php55-solr php55-ssh2 php55-sqlite php55-xmlrpc php55-xsl php55-zip

Add Apache to your $PATH (optional)

ZSH

nano ~/.zshrc

or Bash:

nano ~/.bash_profile

Add the following line

export PATH=/opt/local/apache2/bin:$PATH

Configure Apache to use PHP module

sudo /opt/local/apache2/bin/apxs -a -e -n php5 /opt/local/apache2/modules/mod_php55.so

Select newly compiled PHP binary as the default

Probably only necessary if you are upgrading from an older version Hat Tip

sudo port select --set php php55

Install the php.ini

sudo ln -s ~/Documents/configs/PHP/fat-tony.local.php55.ini /opt/local/etc/php55/php.ini

Fix the GeoIP install

If you’re using the free GeoLite database PHP will probably not find it in the default install location.

sudo ln -s /opt/local/share/GeoIP/GeoIP.dat /opt/local/share/GeoIP/GeoIPCity.dat

Install Percona DB (MySQL replacement)

time sudo port install percona percona-server

I didn’t install percona-toolkit because it wanted to install MySQL due to a dependency

Add Percona (MySQL) to you $PATH (optional)

ZSH

nano ~/.zshrc

or Bash:

nano ~/.bash_profile

Add the following line

export PATH=/opt/local/lib/percona/bin:$PATH

Install your my.cnf if you have one

MacPorts’ MySQL looks for my.cnf in the standard paths as defined by MySQL

You can put this in the global spot: /etc/my.cnf or the one specific to this MySQL install /opt/local/etc/percona/my.cnf

sudo ln -s ~/Documents/configs/MySQL/fat-tony.my.cnf /opt/local/etc/percona/my.cnf

NOTE: You probably need to update the mysql.sock paths in your php.ini to reflect /opt/local/var/run/percona/mysqld.sock. There are 3 possible places you may need to set this.

If this is a fresh MySQL install and you're not re-using existing data install the default tables

sudo -u _mysql /opt/local/lib/percona/bin/mysql_install_db

Start up MySQL

This installs and activates a launchd item.

NOTE: Do not be confused by MacPorts' documentation referring to StartupItems. StartupItems is their term for special scripts that create launchd items I have no ide why they would choose terminology that makes you think it is a 10.4 (pre-launchd) StartupItem (which are deprecated).

sudo port load percona-server

To stop MySQL use

sudo port unload percona-server

Run MySQL's built-in script for hardening the security of your install

sudo /opt/local/lib/percona/bin/mysql_secure_installation

If you don’t set a root password when it asks you to just ring your call button, and Tommy will come back there and hit you over the head with a tack hammer because you are a retard

If this is not a new install, upgrade your existing tables

sudo /opt/local/lib/percona/bin/mysql_upgrade -uroot -p

Install Git

time sudo port install git-core

Install some deployment tools

time sudo port install ruby rb-rubygems
time sudo gem install capistrano capistrano-ext capistrano-mailgun rack

Start Apache

sudo port load apache2

Install AutoJump

time sudo port install autojump
[mysqld]
# Set minimum index length to 2 characters
ft_min_word_len=2
# Set utf8 as the default character set
character-set-server=utf8
[client]
# Set utf8 as the default character set
default-character-set=utf8
[mysqldump]
default-character-set=utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment