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

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:
phpize # prepares the PHP extension for compiling
./configure
make
sudo make install - Now CD into the extracted libmcrypt folder and run these commands:
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-trackingfollowed by:
make -j6And finally:
sudo make install - Now change directories to /SourceCache/php-5.x.x/ext/mcrypt and run the following commands:
phpizeFollowed 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-configAnd then:
make -j6And finally:
sudo make install - Edit /etc/php.ini (if it doesn't exist then:
sudo cp /etc/php.ini.default /etc/php.inifirst - Add the following lines to the .ini file in the Dynamic Extensions section:
extension=mcrypt.so
extension=uploadprogress.so - Update the following lines to make MySQL work properly:
pdo_mysql.default_socket= /tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
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/libphp5.so - 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).






Comments
This was a great read, I
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.
Thanks.
php 5.2 and 5.3
were you able to make both php 5.2 and 5.3 working together in mac?
phpize
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
phpize again
Same as wza here, any ideas?