Setting up your first development *AMP stack on OS X using MacPorts

This type of ‘howto’ lives in many blogs on the ‘net.  This is my latest version.

First, download macports from and install.   Nothing is foolproof, but, by using macports, you will save yourself a ton of time futzing around with stuff that won’t matter much later on.  This step will save you the most time.

Also, if you are REALLY knew, please note that in the commands to follow, you don’t need the “$” that precedes the command. The $ comes from your terminal prompt. And, “#” typically denotes a comment or a note. So, if you see #, understand that what follows is some type of instruction for you to follow, not a command in the terminal.

Next step is optional because it’s personal preference, but, you decide.  Open a terminal and execute the following command:

# Displays all files in Finder.  Optional: personal preference.
$ defaults write AppleShowAllFiles YES
# Relaunch Finder

# Update MacPorts
$ sudo port selfupdate
$ sudo port upgrade outdated

# Install MySQL
$ sudo port install mysql5-server
$ sudo -u _mysql mysql_install_db5
$ sudo mysqld_safe5 &
$ sudo /opt/local/lib/mysql5/bin/mysql_secure_installation
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

# Install Apache, PHP (with PEAR), PHP MySQL bindings
$ sudo port install apache2
$ sudo port install php5 +apache2 +pear
$ sudo port install php5-mysql

# Configure Apache
# The following line may not be necessary
? sudo cp /opt/local/apache2/conf/httpd.conf.sample  /opt/local/apache2/conf/httpd.conf
$ cd /opt/local/apache2/modules
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5"
$ sudo nano /opt/local/apache2/conf/httpd.conf
# Change DocumentRoot to whatever (e.g. /Users/michael/Sites
# Change <directory "{old DocumentRoot}"> to <directory "{new DocumentRoot}">
# In that <directory "{new DocumentRoot}"> section change to the following.
# Options Indexes FollowSymLinks MultiViews
# AllowOverride All
# In  section, add the following two lines
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

# Configure PHP
$ sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini
$ sudo nano /opt/local/etc/php5/php.ini
# set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to
# /opt/local/var/run/mysql5/mysqld.sock

# Start Apache
$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
# Hopefully you'll get a window asking if httpd can accept incoming requests.  Approve it.

# Add DB and tables to MySQL for easy WordPress install
$ mysql5 -u root -p
> CREATE DATABASE putyourdbnamehere;
> GRANT ALL PRIVILEGES ON putyourdbnamehere.* TO "usernamehere"@"localhost" IDENTIFIED BY "yourpasswordhere";

# Install and Configure phpMyAdmin (will need to restart Apache when done)
$ sudo port install phpmyadmin
$ sudo nano /opt/local/apache2/conf/httpd.conf
# Add section
# <Directory "/opt/local/www/phpmyadmin/">
#     Options Indexes MultiViews
#     AllowOverride None
#     Order allow,deny
#     Allow from all
# In  section add the following
# Alias /phpMyAdmin "/opt/local/www/phpmyadmin"

$ sudo nano /opt/local/www/phpmyadmin/
# See http://www.phpmyadmin.netdocumentation/Documentation.html#config
# Fill in $cfg['blowfish_secret']
# Set $cfg['Servers'][$i]['auth_type'] = 'config';
# Add $cfg['Servers'][$i]['user'] = 'root';
# Add $cfg['Servers'][$i]['password'] = '{root password}';

$ sudo /opt/local/apache2/bin/apachectl {start|restart|graceful|graceful-stop|stop}
$ sudo /opt/local/share/mysql5/mysql/mysql.server {start|stop|restart|reload|force-reload|status}
%d bloggers like this: