Memcached with PHP on Mac OS X
Saturday, October 18th, 2008Nate Haug provides a great script for installing memcached along with some very detailed instructions on setting up a sandbox environment. I’m not using his MAMP sandbox, instead opting for the built in PHP / Apache install, so I needed to change a few things from his tutorial. My system is a fully updated Intel MacBook Pro running OS X 10.5.5 with the Xcode tools installed - YMMV. PHP is currently reporting version 5.2.6.
- I added my revised start script for memcached.
- The PHP version that ships with OS X doesn’t have PECL, so I downloaded the source and compiled manually.
phpize; configure; make; sudo make install - Edit to /etc/php.ini: Changed: extension_dir = /usr/lib/php/extensions/no-debug-non-zts-20060613/
- Edit to /etc/php.ini: Added: extension=memcache.so
You can skip his Apache scripts. Restart apache by restarting Web Sharing in the System Preferences.
The major changes I made from Nate’s memcached startup script were the singular instance and binding the service to localhost (127.0.0.1) only. This keeps memcached slightly more secure by only having it listen on the loopback adapter. If you need more space, just change the -m attribute to be higher; it’s measured in MB.
# /bin/sh memcached -m 1 -l 127.0.0.1 -p 11211 -d |
NOTE: As with any other service running on your system, opening a web server exposes your system to potential attack and worse. Be sure to keep production data away from your test environment. Someone at Starbucks, sharing your WiFi connection, may be surfing your development site too. Consider yourself warned!
I was struggling with MySQL Query Browser, trying to make some minor modifications to a schema recently when a friend, aptly named Erik, from