http://blog.xeonxai.com/2009/09/02/146/
This will help you to setup imagick, magicwand, xdebug, mcrypt and memcached for Snow Leopard’s bundled PHP 5.3.0. Please do expect the installation of ImageMagick to take a bit of time, as it requires a large number of packages. I’m doing it all my preferred way. If you have another way that is faster or better, I’d be glad to take your suggestions and make this tutorial more streamlined.
Step 1:
Make sure you have XCode 3.2 for Snow Leopard installed, from the Snow Leopard install DVD.
Step 2:
Download MacPorts for Mac OS X 10.6 Snow Leopard here.
If you have previously installed MacPorts and installed software with it in Mac OS X 10.5, run this first to remove it, as it won’t work in Snow Leopard anymore.
In Terminal:
sudo rm -rf /opt/local \ /Applications/MacPorts \ /Applications/DarwinPorts \ /Library/Tcl/macports1.0 \ /Library/Tcl/darwinports1.0 \ /Library/LaunchDaemons/org.macports.* \ /Library/StartupItems/DarwinPortsStartup \ /Library/Receipts/MacPorts*.pkg \ /Library/Receipts/DarwinPorts*.pkg \ ~/.macports
Step 3:
Open the MacPorts-1.8.0-10.6-SnowLeopard.dmg file, and install the MacPorts package file.
Step 4:
To hide the /opt folder from Finder view that is visible after installing MacPorts.
In Terminal:
sudo chflags hidden /opt
Step 5:
By default, MacPorts for Snow Leopard should use x86_64 arch instead of ppc/i386, so you shouldn’t have to worry much here.
This part most likely will take the longest of all things in the tutorial, as it requires a large group of individual packages. You can cook dinner, eat it, and you might still be waiting for this to complete after you’ve finished eating. It took about a half hour for it to complete on my MacBook.
In Terminal:
sudo port install imagemagick
Step 6:
Unpack the file imagick-2.3.0.tgz.
In Terminal:
cd ~/Downloads/imagick-2.3.0/imagick-2.3.0 phpize ./configure --with-imagick=/opt/local make cd modules sudo cp imagick.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Step 7:
Download magickwand here.
Unpack the file MagickWandForPHP-1.0.8.tar.gz.
In Terminal:
cd ~/Downloads/MagickWandForPHP-1.0.8/ phpize ./configure --with-magickwand=/opt/local make cd modules sudo cp magickwand.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Step 8:
Unpack the file xdebug-2.0.5.tgz.
In Terminal:
cd ~/Downloads/xdebug-2.0.5/xdebug-2.0.5 phpize ./configure make cd modules sudo cp xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Step 9:
In Terminal:
sudo port install libmemcached
When it completes, type this into Terminal:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.memcached.plist
Step 10:
Unpack the file memcached-1.0.0.tgz.
In Terminal:
cd ~/Downloads/memcached-1.0.0/memcached-1.0.0/ phpize ./configure --with-libmemcached-dir=/opt/local make cd modules sudo cp memcached.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Step 11:
Unpack the file libmcrypt-2.5.8.tar.bz2.
In Terminal:
cd ~/Downloads/libmcrypt-2.5.8/ ./configure --disable-posix-threads --enable-static make sudo make install
Step 12:
Download PHP 5.3.0 source code for the mcrypt extension here.
Unpack the file php-5.3.0.tar.gz. We will only need to use the code within the ext/mcrypt directory. No need to compile all of PHP for this.
In Terminal:
cd ~/Downloads/php-5.3.0/ext/mcrypt phpize ./configure make cd modules sudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Step 13:
In Terminal:
cd /etc sudo cp php.ini.default php.ini sudo pico php.ini
Search for:
display_errors
Set this to:
display_errors = On
Search for:
html_errors
Set this to:
html_errors = On
I placed the following after all the commented out lines for extensions:
;;;;;; extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so xdebug.default_enable = On xdebug.collect_params = 4 xdebug.trace_format = 1 xdebug.show_local_vars = On xdebug.dump_globals = On xdebug.show_exception_trace = On xdebug.collect_assignments = 1 ;;;;;;
Set your default timezone. I’ll show mine as an example.
date.timezone = America/New_York
Set your mysql default port.
mysql.default_port = 3306
Press Control-X to exit, it will ask if you want to save changes, so press Y for Yes, and press Enter save and exit completely.
Step 14:
Restart Apache.
In Terminal:
sudo apachectl graceful
That should do it, as this is the exact steps I took to install all of these just now. And everything worked for me just as typed.
Hope this helps you out.
Enjoy.
40 Comments
Thank you. You saved me alot of heartbreak w/ this tutorial.
Are their any other extensions you wish I should include with my tutorial?
Thank you very very much. This is a great walk through. The timezone setting didnt work for me. I had to define it as:
date.timezone = Etc/GMT-5
Otherwise I’d get the error (in the php.ini):
Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
Do you have any suggestions for other PHP extensions I should include?
Xeon Xai,
You are an inspiration to us all! Love the blog.
Perfect! Just the help I needed. Saved me days. Thanks!
If you need help with any other extensions, let me know and I will include them here.
Is anyone else having problems with Xdebug were the values of variables are be displayed as Uninitialized when you are inside a function?
Dennis Redies, can you give more detail on your xdebug issues?
Thanks,
Xeon Xai
Hi Xeon
Thanks for your tutorial (PHP extension) , it help me to solved an issue I had with phpMyAdmin & SL…(I am not PHP dev, rather RubyOnRails… but I like phpMyAdmin)
On you advice I bought VirtualHostX …
Do you mind if I translate your tutorial into French for non-english readers ? it will be my FIRST article on my FIRST blog ….
Yves
Mahalo so much for posting this—I’d been using some beta instructions for a couple of servers up until the official release last week, and this is the first, “official” 10.6 release instructions I’ve seen, and they were tremendously helpful. You shoud post a PayPal link on this page for people (like myself) for donations.
I’m always happy to help.
APC:
* Install pcre lib with macports
* download the appropriate version of the APC package http://pecl.php.net/package/APC
* Unpack it
* cd APC*
* Run phpize
* MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS=”-arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch x86_64 -g -Os -pipe” LDFLAGS=”-arch x86_64 -bind_at_load” CPPFLAGS=”-I/opt/local/include” ./configure
* cd modules
* sudo cp apc.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
enjoy
cirpo
@cirpo, thanks for the APC entry. A couple issues I experienced:
* I needed to soft-link to the pcre.h file, i.e., “ln -s /opt/local/include/pcre.h /usr/include/php/ext/pcre/”
* you also might need to add “–with-pcre-regex=/opt/local/include” AND/OR “–with-pcre-dir=/opt/local/include” to the .configure command.
* and don’t forget to run “make”
Dude… you are a god my friend. Been trying to figure this out for days now. So happy to not have to use Entropy anymore.
Big thanks!!!
pali
Thanks, if you have any troubles with any other extensions you want, let me know.
Thanks for the wonderful tutorial! I am almost through this upgrade to 10.6.
However I am having one problem with libmcrypt-2.5.8.
I get the following error after attempting to run the ‘make’ command while building this module:
make[2]: *** [libmcrypt.la] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Do you have any idea what I might be doing wrong?
Thanks!
Can’t thank you enough for this tutorial!
An addition could be GhostScript. I got it working by:
sudo port install ghostscript
And then making an alias for Apache:
sudo ln -s /opt/local/bin/gsc /usr/bin/gs
Had no idea what I was doing but I got it working.
It would also be helpful if you would note what differs Leopard from Snow Leopard installation. And if there is anything to keep in mind when installing on OS X Server instead of OS X.
well done! you saved some hours
Forgive me for asking, but why not just install and manage PHP5 through macports? macports has ports for php5, php5-xdebug, php5-apc, etc.
Another question I have is why did you use macports to install some libraries, like imagemagick, but then compile from source like libmcrypt?
That being said, this does give a great overview of how to compile php extensions and the many ways of integrating libraries into php. These techniques are good too if you ever need to make extensions for ZendServer on OSX as well.
i think i really need you help, sorry.. i’m totally new in this and i was trying to make work php in my imac and i did but when i get to the point to try to test phpbb in my localhost i get really confused.
i followed this steps http://wiki.phpbb.com/Localhost to make a test in my localhost but when i tried to make a database i couldn’t because mcrypt then i search in the web and i found your post, and i follow your steps. but i don’t know why it didn’t work. can you give me an advice?i will appreciate it a lot this tuesday i will make a clean install of snow leopard so i [please if you can] can you tell me how to achieve what i want?
I actually used PECL to install imagick.
You’ll still need to install ImageMagick via MacPorts but after that step install pear-pecl using the go-pear.php script. (http://pear.php.net/go-pear).
After those are both run go to /usr/local/bin and run
pecl install imagick
When it asks you for the ImageMagick installation folder tell it to look in /opt/local
Make sure and add the imagick extension to your php.ini, mine looks like:
extension=imagick.so
I’ve found this method to be much easier and you’ll avoid steps 6-13.
Hope that helps somebody.
Great article, worked excellent for me. I also installed ghostscript.
Wow!!! I’m so grateful for this. Thanks a lot for sharing! –Blog goes straight into rss-reader
Really great work, thank you very much for having spent your time to help us.
It worked like a charm with only copy/paste actions.
Thank you,
Chris
Mac OS X 10.6.1
Xcode 3.2.1
It sure was nice to get rid of phpmyadmin’s complaint of no mcrypt! Thanks for the great tutorials.
Thank You very much. Not only did this solve my mcrypt issue but gave me insight to a few other things. Worked perfectly. I found a couple differences however.
1. MacPorts-1.8.0-10.6-SnowLeopard.dmg – I found it to be MacPorts-1.8.1-10.6-SnowLeopard.dmg now
2. cd ~/Downloads/xdebug-2.0.5/xdebug-2.0.5 & cd ~/Downloads/memcached-1.0.0/memcached-1.0.0/ – I did not have a second level dir just ~/Downloads/xdebug-2.0.5 & cd ~/Downloads/memcached-1.0.0
Thank you again for your great post!
Freakin’ fantastic! This has saved me a lot of headaches. Thank you so much.
Would you consider adding a robust version of gd2 to the mix? (The 10.6 Server version does not include Freetype, which is causing me some problems. I thought your inclusion of ImageMagick was going to solve those, but it hasn’t.)
Thanks for the tutorial. It really helped my out.
One question: How do you know when to add –with-MODULE_NAME=/opt/local to ./configure?
The -with-module-name=/opt/local is for when you have to use a binary file in that directory, or the directory that you tell it to find the binary and lib files it will need to link to.
Not all will require it. Things like imagick or magicwand will need it. Though most will not unless they need to link to a static binary or lib file.
Hi,
Thanks for this tuto that save me lot of time and stress
Btw, I tried to used this method to compile and install the gettext extension in php but it doesn’t seem to work.
Do you know if this method can be used ? Have you tried with the gettext php extension ?
Thanks a lot for all this work.
Nico
@ Xeon Xai: Tanks for the reply.
@ #23: I was actually using this tutorial because I needed to install gettext
I think what i did was:
$ sudo port install gettext
$ cd ~/Downloads/php-5.3.0/ext/gettext
$ phpize
$ ./configure –with-gettext=/opt/local
$ make
$ cd modules
$ sudo cp gettext.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
$ sudo apachectl graceful
I’ve tried many things to get it to work but I think this is what finally made it. But don’t just copy/paste this. It might contain typos. Of course you need to download php first.
Thanks for your help.
I tried your procedure and :
- compile ok
- install ok
- loaded in php ok (phpinfo() reports it as enabled)
but it does not work
, at least with Gallery 2.3.1
When I install gallery, I have the following message during the gettext test :
Your PHP is missing the function ‘bind_textdomain_codeset’. This means Gallery may display extended characters for some languages
An idea ?
Tks
Nico
I also need to get the function bind_textdomain_codeset enabled, or in some way working! Gettext now is enabled, but it does not show my local norwegian characters properly! Anybody?
This is great, exactly what I needed!
Thanks very much
Thanks for reading and enjoying the work.
Awesome tutorial! Thanks so much, saved me a ton of time and energy. Any chance you can add the zip extension to your tutorial.
Thank you for this great information. I’d like to know where you learned how to install the PHP extensions. Is this in the PHP documentation?
I learned all my PHP extension skills from working with PHP and Mac OS X for many years. Installation for PHP extensions vary slightly for each operating system and configuration. You can read more about it in the PHP.net site docs.
I’m having trouble getting imagick to install with MAMP. The imagick.so file that is compiles is x86_64 and I think MAMP requires a universal or i386. Any tips on how I might be able to overcome this issue? When I start MAMP, my PHP log says:
[17-Feb-2010 10:42:48] PHP Warning: PHP Startup: Unable to load dynamic library ‘/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so’ – (null) in Unknown on line 0
This is also happening with magickwand.so
5 Trackbacks
[...] plus de modules qu’avant, maintenant s’il vous manque des modules, vous pouvez vous inspirer de ce guide (en anglais) pour installer des modules supplémentaires à la version de PHP fournie par Apple. Je [...]
[...] du tutoriel de Xeon Xai, après execution… of [...]
[...] Go and see Xeon Xai’s blog post Snow Leopard PHP Extensions Installation Tutorial for how to add to mcrypt and other useful PHP extensions that Apple doesn’t include. The [...]
[...] Installing PHP Extensions Imagick, Magickwand, Memcached, MCrypt [...]
[...] my development environment on my work Mac…. http://blog.xeonxai.com/2009/09/02/146/ This was easier in Ubuntu… [...]