Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Install MAMP Development stack on Mountain Lion using MacPorts

NOTE: 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 -> 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.)

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

time sudo port install php54 +apache2 php54-apache2handler php54-curl php54-gd php54-exif php54-geoip php54-http php54-iconv php54-imagick php54-imap php54-mbstring php54-mcrypt php54-mysql php54-pear php54-pcntl php54-posix php54-soap php54-sockets php54-sqlite php54-xmlrpc php54-xsl php54-openssl php54-xdebug php54-zip

Add Apache to your $PATH (optional)

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_php54.so

Select newly compiled PHP binary as the default

Probably only necessary if you are upgrading from PHP 5.3 Hat Tip

sudo port select --set php php54

Install the php.ini

sudo ln -s /opt/local/etc/php54/php.ini-development /opt/local/etc/php54/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

Configure httpd.conf Files

/opt/local/apache2/conf/httpd.conf

Add the following if your htdocs is somewhere in your home directory where 'reecefowell' is my user, use your own username. And set group to 'staff'.

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

User reecefowell
Group staff

</IfModule>
</IfModule>

Fix annoying message regarding fully qualified server name by adding:

ServerName: localhost:80

Ensure these sensible defaults:

<Directory />
    Options All FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

<Directory "/opt/local/apache2/htdocs">

    Options All Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

Include conf/extra/mod_php.conf
Include conf/extra/httpd-vhosts.conf

Add the following files:

/opt/local/apache2/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName root.local
    DocumentRoot /Users/reecefowell/Projects/htdocs
</VirtualHost>

/opt/local/apache2/conf/extra/mod_php.conf

<IfModule mod_php5.c>

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

</IfModule>

Install MySQL 5.5

time sudo port install mysql55 mysql55-server

Add MySQL to you $PATH (optional)

nano ~/.bash_profile

Add the following line

export PATH=/opt/local/lib/mysql55/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/mysql55/my.cnf

[mysqld]
# Set the datadir
datadir=/var/mysqldata

# 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

The my.cnf should also set the datadir where your data files reside. I like /private/var/mysqldata (to avoid collisions with Apple’s old location of /private/var/mysql)

sudo mkdir -p /private/var/mysqldata
sudo chmod 750 /private/var/mysqldata
sudo chown _mysql /private/var/mysqldata

NOTE: You might want to update the mysql.sock paths in your php.ini to reflect /opt/local/var/run/mysql55/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/mysql55/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 mysql55-server

To stop MySQL use

sudo port unload mysql55-server

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

sudo /opt/local/lib/mysql55/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/mysql55/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 rack
time sudo gem install capistrano-mailgun

Start Apache

sudo port load apache2

Optionally Add PhpMyAdmin Support

/opt/local/apache2/conf/extra/httpd-phpmyadmin.conf

AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/opt/local/www/phpmyadmin$1"

<Directory "/opt/local/www/phpmyadmin">
    Options -Indexes
    AllowOverride None
	Order allow,deny
	Allow from all

	LanguagePriority en de es fr ja ko pt-br ru 
	ForceLanguagePriority Prefer Fallback
</Directory>

<VirtualHost *:80>
	ServerName mysql.local
    DocumentRoot /opt/local/www/phpmyadmin

	<Directory "/opt/local/www/phpmyadmin">
		Options -Indexes
		AllowOverride None
		Order allow,deny
		Allow from all

		LanguagePriority en de es fr ja ko pt-br ru 
		ForceLanguagePriority Prefer Fallback
	</Directory>
</VirtualHost>

Add to your /opt/local/apache2/conf/httpd.conf

Include conf/extra/httpd-phpmyadmin.conf

Install PhpMyAdmin

time sudo port install phpmyadmin +php54

Configure

cd /opt/local/www/phpmyadmin
sudo mkdir config
sudo chmod 777 config
sudo cp config.sample.inc.php config/config.inc.php
sudo chmod 777

In the browser go to http://mysql.local/setup or http://localhost/phpmyadmin/setup and click 'New Server' then set the following:

  1. Server hostname: localhost
  2. Server socket: /opt/local/var/run/mysql55/mysqld.sock
  3. Connection type: socket
  4. PHP extension to use: mysqli

Go to the authentication tab:

  1. Authentication type: config
  2. user for config auth: root
  3. password for config auth: root

click save and then save again, go to the command line again and type:

cp config/config.inc.php .

sudo rm -rf config/
sudo chmod 644 config.inc.php

sudo port unload mysql-server55
sudo port load mysql-server55
# Use default MacPorts settings
#!include /opt/local/etc/mysql55/macports-default.cnf
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Set utf8 as the default character set
default-character-set=utf8
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
# Set minimum index length to 2 characters
ft_min_word_len=2
# Set utf8 as the default character set
default-character-set=utf8
[mysqld]
#user = mysql
#pid-file = /var/run/mysqld/mysqld.pid
#socket = /var/run/mysqld/mysqld.sock
socket = /opt/local/var/run/mysql55/mysqld.sock
port = 3306
#basedir = /user
datadir = /var/mysqldata
#tmpdir = /tmp
#lc-messages-dir = /usr/share/mysql
skip-external-locking
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#key_buffer = 16M
#max_allowed_packet = 16M
#thread_stack = 192K
#thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
#query_cache_limit = 1M
#query_cache_size = 16M
# Set minimum index length to 2 characters
ft_min_word_len=2
# Set utf8 as the default character set
character-set-server=utf8
[mysqldump]
default-character-set=utf8
@reecefowell

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.