Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jwcobb/4210358 to your computer and use it in GitHub Desktop.
Save jwcobb/4210358 to your computer and use it in GitHub Desktop.
Install MAPP/MAMP stack on OS X Mavericks using MacPorts.

Install MAPP (MAMP) stack on Mavericks using MacPorts

I keep most of my Apache/PHP/Percona (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.

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

sudo xcodebuild -license

Install MacPorts

Use the Mac OS X Mavericks 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 Perl 5.16

WTF‽ I thought you said this was going to tell me how to install PHP‽

perl5 is a depency of one of curl’s dependencies (curl-ca-bundle) and by default perl 5.12 will be installed, but later when we install percona-tookit we will need perl 5.16 so just go ahead and force perl 5.16 here so you don't end up with both 5.12 and 5.16.

There is no harm in having multiple versions installed, but installing only one will save a little bit of compile time.

time sudo port install perl5.16 perl5 +perl5_16

Install cURL with the SSL variant

time sudo port install curl +ssl

Install Percona Server

Percona Server is an enhanced, drop-in MySQL® replacement and it isn’t controlled by Oracle.

A free open source solution, Percona Server is a MySQL alternative which offers breakthrough performance, scalability, features, and instrumentation. Self-tuning algorithms and support for extremely high-performance hardware make it the clear choice for organizations that demand excellent performance and reliability from their MySQL database server.

time sudo port install apr-util +percona percona +openssl percona-server intltool +perl5_16

Install Percona Toolkit

Percona explains these best:

Percona Toolkit for MySQL is a collection of advanced command-line tools used by Percona MySQL Support staff to perform a variety of MySQL server and system tasks that are too difficult or complex to perform manually…

time sudo port install p5.16-dbd-mysql +percona percona-toolkit +perl5_16

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’ Percona/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 install /opt/local/etc/percona/my.cnf

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

If you do not have a my.cnf file or don't know where to start, the Percona Configuration Wizard for MySQL will build you a good base. The my.cnf file here is for my development machine which is a MacBook Pro “Core i7” 2.7 15" Retina 2013 with 16GB of RAM.

Install default tables

If this is a fresh Percona/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 Percona/MySQL

This installs and activates a launchd item.

Do not be confused by MacPorts' documentation referring to StartupItems. StartupItems is their term for special scripts that create launchd items I have no idea 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 Percona/MySQL use

sudo port unload percona-server

Run Percona/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 PHP 5.5 and Apache 2

time sudo port install apr-util +percona 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-mailparse php55-mbstring php55-mcrypt php55-mysql +percona php55-openssl php55-pdflib php55-pear php55-posix php55-soap php55-sockets php55-solr php55-ssh2 php55-sqlite php55-xmlrpc php55-xsl php55-zip

If this is your development box also install Xdebug.

time sudo port install php55-xdebug

Please don’t install Xdebug on production machines!

Designate PHP 5.5 as the active version.

Only really necessary if you are upgrading from an older version of PHP (Hat Tip) but doesn’t hurt to do it anyways.

sudo port select php php55

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

Install the php.ini

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

NOTE: If you are also installing Percona 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.

  • mysql.default_socket
  • mysqli.default_socket
  • pdo_mysql.default_socket

Install Cronolog to rotate your log files

If you want to split your log files up into usable chunks.

time sudo port install cronolog

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

Start Apache

sudo port load apache2

To stop Apache use

sudo port unload apache2

Install Some Additional Tools For Development

Install AutoJump

autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line. Directories must be visited first before they can be jumped to.

time sudo port install autojump

Install Capistrano for deployment

First we will install rvm for Ruby management.

curl -L https://get.rvm.io | bash

Now install Ruby. Change the version if necessary, but I chose ruby-2.0.0-p247, which is the same one that Apple installs by default in Mavericks.

rvm install ruby-2.0.0-p247

I received an error Updating certificates in '/etc/openssl/cert.pem'. mkdir: /etc/openssl: Permission denied but chose to ignore. Feel free to provide some info in the comments

Tell rvm we want to use the ruby we just installed

rvm --default use ruby 2.0.0

I have some projects that are still using Capistrano 2 and some that are using the newer Capistrano 3 so I create a gemset for each. Your don’t need to make a gemset for your capistrano if you only use one version, but I only use Ruby for deploying and I like that having them gemsets makes it clear to me which version I am using. You could just install Capistrano in your default gemset if you like.

rvm gemset create capistrano3
rvm gemset create capistrano2

Finally we can actually install Capistrano. Also include @spike666’s Capistrano::Mailgun so you can send emails upon deploy.

Start with Capistrano 3. Also make this the default gemset.

rvm gemset use capistrano3 --default
gem install capistrano capistrano-mailgun

Now Capistrano 2 if you need it for legacy projects.

rvm gemset use capistrano2
gem install capistrano capistrano-mailgun
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
# Configuration name fat-tony generated for j at 2013-10-24 19:39:07
##
# I am not 100% sure that the UTF8 settings in the sections below are still required.
# I cannot find any documentation of what the default charsets and collations are for
# Percona Server 5.5. Commenting those options below out resulted in the server still
# showing them set as UTF8, but it doesn’t seem to hurt to keep them in there.
[mysql]
# CLIENT #
port = 3306
socket = /opt/local/var/run/percona/mysql.sock
# Set utf8 as the default character set
character-set=utf8
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = MyISAM
socket = /opt/local/var/run/percona/mysql.sock
pid-file = /opt/local/var/db/percona/mysql.pid
# MyISAM #
key-buffer-size = 6G
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /opt/local/var/db/percona/
# BINARY LOGGING #
log-bin = /opt/local/var/db/percona/mysql-bin
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 32M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 32M
# LOGGING #
log-error = /opt/local/var/db/percona/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /opt/local/var/db/percona/mysql-slow.log
# CUSTOMIZED OPTIONS #
# Set utf8 as the default character set
character-set-server=utf8
collation_server = utf8_general_ci
# Eliminate stop words
ft_stopword_file=
# Set minimum index length to 2 characters
ft_min_word_len=2
[mysqldump]
# CUSTOMIZED OPTIONS #
# Set utf8 as the default character set
character-set=utf8
@ramasterson
Copy link

Thanks for this- great walk-through.

After getting this set up, I was having issues running .php scripts on my localhost. Basically, if I went to localhost/test.php, where test.php was a file that I added to /opt/local/apache2/htdocs, apache was just returning the code from the .php script, not actually rendering it.

To fix this, I added this to /opt/local/apache2/conf/httpd.conf:

AddType application/x-httpd-php .php

@ajardin
Copy link

ajardin commented Dec 2, 2013

Hi,

Thanks for this really great walkthrough!

I used it during my migration to Mavericks but I have encountered a little problem with the InnoDB engine.
Just after the installation, I've checked the available MySQL engines.

mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| MyISAM             | DEFAULT | MyISAM storage engine                                                      | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

Obviously, there was a problem with the InnoDB engine. So I checked my MySQL logs and I found this error:
InnoDB: Error: log file ./ib_logfile0 is of different size...

If you have the same error, you will probably need to follow these steps:

  • stop the MySQL server
  • locate the logs directory and the InnoDB files (ib_logfile*)
  • move these files outside the directory (we will delete them later)
  • start the MySQL server

Now if you check the MySQL error logs. You should see some messages saying that the previously moved logs files don’t exist. But they were generated again and the server has restarted normally.

And now the InnoDB engine must be available!

mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| InnoDB             | YES     | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MyISAM             | DEFAULT | MyISAM storage engine                                                      | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
6 rows in set (0.00 sec)

If this is the case, you can delete the old InnoDB files and enjoy your new installation. ;-)

@djmadcat
Copy link

We can set percona as default mysql package:
sudo port select mysql percona

And after MacPorts installed, we can use
sudo port -v selfupdate
instead of
sudo /opt/local/bin/port -v selfupdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment