Setting up Apache MySQL and PHP on OS X without using MAMP

drupal planet
For a long time I've been using MAMP to manage my local dev environment, but over the past few days I've been cleaning up my system and un-installing anything I don't really need. I checked this morning and found that OS X has a newer version of Apache than my install of MAMP did, so seemed a prime target to cull from my machine. Here are the steps I took:
  • Create sql dumps of any databases you want to restore
  • Uninstall MAMP Pro if you have it
  • Drag the MAMP folder to Trash
  • Install MySQL
  • Configure PHP
  • Install phpMyAdmin (optional)
  • Import DB backups
  • Set up vhosts
  • Enjoy
I'm going to assume you can figure out how to do the first few steps yourself, here is how I installed and configured the new environment:

Install MySQL

Download the MySQL Installer package for Mac OS X, 32 or 64 bits depending on your machine. (I used 64).
  • Install everything in the package in this order: mysql, the startup item, the preference pane.
  • Start MySQL in the preference pane.
  • Test it's working by typing the following in a terminal: /usr/local/mysql/bin/mysql
  • Add to the system $PATH so you can just type mysql at prompt by typing the following at terminal prompt: sudo nano /etc/paths And add the following to the bottom of the file: /usr/local/mysql/bin/ hit CTRL+X to save and Y to confirm.

Configure PHP

There are some PHP extensions that aren't part of the default install on OS X, here is how to add them and add some other required options to php.ini:
  • Download the PHP source code.
  • Download the PECL uploadprogress extension.
  • Download libmcrypt-2.5.8 NOTE: make sure to get libmcrypt and not mcrypt.
  • Grab XCode from either of these sources App Store or Apple Developer Connection.
  • Next, create a directory at root called ‘SourceCache’ and extract the files into it.
  • From a terminal prompt CD into the extracted uploadprogress folder and run these commands:
    1. phpize # prepares the PHP extension for compiling
    2. ./configure
    3. make
    4. sudo make install
  • Now CD into the extracted libmcrypt folder and run these commands:
    1. MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
    followed by: make -j6 And finally: sudo make install
  • Now change directories to /SourceCache/php-5.x.x/ext/mcrypt and run the following commands: phpize Followed by: MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config And then: make -j6 And finally: sudo make install
  • Edit /etc/php.ini (if it doesn't exist then: sudo cp /etc/php.ini.default /etc/php.ini first
  • Add the following lines to the .ini file in the Dynamic Extensions section:
  • Update the following lines to make MySQL work properly:
    1. pdo_mysql.default_socket= /tmp/mysql.sock
    2. mysql.default_socket = /tmp/mysql.sock
    3. mysqli.default_socket = /tmp/mysql.sock
  • Enable the inbuilt PHP by editing the apache config file: sudo nano /etc/apache2/httpd.conf and removing the # charachter in front of the following line: # LoadModule php5_module libexec/httpd/
  • Restart apache to make the changes take effect: sudo apachectl restart
  • Now you can delete the SourceCache directory from your machine.

Apache vhosts

You can manually create your vhosts manually, or you can use something like VirtualHostX (which I chose to buy, it's still cheaper than buying MAMP Pro).


This was a great read, I remember the pain I went through when switching from a Linux (Ubuntu) environment to Mac. Articles like these were very helpful. Coming from Ubuntu, I was itching for a package manager like apt-get, so I went with MacPorts. I liked the organization it provided and I felt it better mimicked a traditional stack. Just wanted to put it out there for anybody who may be interested. Excellent post.


Submitted by Afraaz on April 27, 2011 - 3:25am

were you able to make both php 5.2 and 5.3 working together in mac?

Submitted by Leandro Nunes on January 2, 2012 - 3:38pm

phpize tells me

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory

Submitted by wza on January 3, 2012 - 12:22am

Same as wza here, any ideas?

Submitted by Julio Moreira on October 13, 2012 - 8:27am

I have the same issue:

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

Submitted by Persa on June 28, 2013 - 12:10am

Where should I keep the Uploadprogress and php-5.5.0 files that were downloaded?
Does it matter if those get deleted after all of these steps?

Submitted by Persa on June 27, 2013 - 11:58pm

I re-read the instructions, disregard this question. I noted that I had to extract the files in my new folder at root. Thanks.

Submitted by Persa on June 28, 2013 - 12:11am

Add new comment