Making Snow Leopard’s PHP 5.3.0 usable in the real world

September 24th, 2009 § 21 comments

Update:

It has been a while since I originally posted this article and somethings have changed. Marc Liyanage has posted his custom PHP 5.3.0 build and, as noted by a comment from Sam, a simple flag would have helped a lot. So…carry on.


As of writing the standard 5.2.x Entropy package from Marc Liyanage does not work with 10.6. This means either a custom compile of PHP 5.2.x and the required extensions or piggybacking the default 5.3.0 install. After spending a few days attempting trying to modify the existing Entropy install, trying to build new plug-ins against it and many other techniques it became clear that the quickest path back to development was to used the 5.3.0 install and provide the missing plug-ins.

What’s missing with the 5.3.0 install

The default Apple install provides many nice plug-ins but thus far there have been a few critical ones noted as missing which require building on your own machine and installing into your PHP’s extension directory. The process is the same for each of these but will be tackled on a one-by-one basis.

Preparaing your environment to build extensions

Compiling PHP extensions is easy, requiring only the PHP source from php.net. Download the PHP source using your browser, cURL or another available method as Snow Leopard lacks wget. Extract the code to a temporary directory, such as ~/source_files/php. Although 10.6 is a 64-bit environment these will be four way builds, just in case Apache, PHP or any other environment calls for 32-bit compiles.

Set up your arguments environment with this command:

CFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64'
LDFLAGS='-O3 -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64'
CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64'

libmcrypt

Download the latest version of libmcrypt from SourceForge and unpack into ~/source_files/libmcrypt. Execute the build with these commands:

cd ~/source_files/libmcrypt/
./configure --disable-posix-threads --disable-shared
make
sudo make install

With libmcrypt properly built and installed in the system all that’s left is building the code provided in the PHP source.

mhash

cd ~/source_files/php/ext/mhash
phpize
./configure
make
sudo make install

mcrypt

cd ~/source_files/php/ext/mcrypt
phpize
./configure
make
sudo make install

mssql

I have not yet attempted an MSSQL extension compilation but I can already assume you’ll need to download FreeTDS before starting. Anybody who gets this done should do us all a favor and post something in the comments.

See also:

§ 21 Responses to Making Snow Leopard’s PHP 5.3.0 usable in the real world"

  • […] compiling PHP extensions until you have enough to get things done. I’ve created a new post on how to get some basic things working and helpful links to other common issues (segmentation faults […]

  • Fred says:

    libmcrypt won’t install with multiple architectures unless you configure it correctly. I kept getting: gcc-4.0: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags

    The secret is ./configure –disable-dependency-tracking

  • PloughGuy says:

    Thanks to Fred, I managed to compile libmcrypt, but neither of the php-530 downloads I brought down contains mcrypt. The tar.gz file does not even have the ext directory.

    Which brings up two questions:

    Do I need mhash for php?
    Why do you have it in your download and I don’t?

    Thanks for any responses,
    PloughGuy

  • PloughGuy says:

    And another thing:

    With libmcrypt installed, I expect that php_info() to return mcrypt information, but I am not seeing it.

    In php.ini, the mcrypt stuff is all commented out, but it claims that the default dir is /usr/local/lib/libmcrypt.

    I have this directory, but it is empty. The libraries /usr/local/lib/libmcrypt.a and /usr/local/lib/libmcrypt.la exist, though.

    Thanks for any suggestions…
    PloughGuy

  • PloughGuy says:

    OK, I have run out of luck.
    Aside from no mhash, as detailed above, I still do not have mcrypt running in php.

    When I run phpmyadmin it tells me that there is no mcrypt available. When I run php_info() there is no mcrypt listed.

    I have a /usr/local/lib/libmcrypt directory but it is empty. I have a /usr/local/lib/libmcrypt.a[l] files, though. I did not see any errors in the sudo make install or in any other steps.

    I have restarted the web server. In php.ini, the mcrypt entries are commented out, but it claims the default to /usr/local/lib/libmcrypt.

    I am totally amazed at how damn tricky this is. The MacPorts people claim they have a solution – couldn’t get that to work. There are a bunch of different instructions on how to build mcrypt from source. They are all different, with different steps, different options. I am starting to think that it would be quicker to buy another machine, install linux, learn how to use it, and get the whole damn thing working there… Aaargh!

  • adam says:

    PloughGuy- You need to install mhash first as it is needed by mcrypt. Remove your mcrypt, configure/make/install mhash then do the same for mcrypt. Then back to instructions to finish off. You should be good to go.

  • PloughGuy says:

    Also needed to add:
    —————–8<—————–
    extension=mcrypt.so
    —————–8<—————–
    back into the new php.ini.

    mcrypt.so is created in
    – /usr/lib/php/extensions/no-debug-non-zts-20090626

    phpinfo() now shows mcrypt, and phpmysql has stopped complaining that it does not exist.

  • PloughGuy says:

    Adam,
    I have downloaded mhash as a separate download because it is not in the php/ext directory. phpize hates it – wants config.m4 which is not there.

    As you can tell, PloughGuy is a php user, not a php setter-upper.
    Thanks for your help…
    PG

  • adam says:

    Just glad you got things working. I’ll update my post with your tips!

  • Gabriel says:

    Hi Adam,

    Thank you for the interesting post.

    When you say:

    “Set up your arguments environment with this command:

    CFLAGS=’-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64′
    LDFLAGS=’-O3 -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64′
    CXXFLAGS=’-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64′”

    What do you mean? Do I have to type those commands in Terminal???

    Thank you for helping!

  • adam says:

    Gabriel-

    Yes, I should have been more clear. Just copy those *FLAGS commands and paste those into your Terminal. Hit return and you’re set! Those just set some flags in the global scope of the Terminal session that the compiler will pick up.

  • jmarquez says:

    PloughBoy,

    How did you fix your last issue?
    I was also missing mhash from the PHP Source, I did have hash though. I downloaded mhash from here..
    http://mhash.sourceforge.net/
    I am having the same issue as you when running phpize for mhash.
    I get this error
    Cannot find config.m4.
    Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module

    I am stuck. How do I proceed?
    Thank you

  • macsucks says:

    I think i buy a windows computer, much easyier. no need to complie

  • hi adam,

    thanks a lot for this walk through; saved me an awful lot of time!

    a few notes you might want to add for clarity:

    – the source which needs to be downloaded is php-5.2.13 (and not php-5.3.2 which is on top of the download page)
    http://nl3.php.net/get/php-5.2.13.tar.bz2/from/a/mirror

    – the mhash extension is not present in the php-5.3.2 source. even though the install from the 5.2.13 source results in a “configure: error: Please reinstall libmhash – I cannot find mhash.h” message, mcrypt installed and works without any issues… looks like mcrypt does not require the mhash extension to be installed

    – as ploughguy already pointed out; the mcrypt extension needs to be activated. simply add: extension=mcrypt.so
    to your php.ini file, restart apache and mcrypt is activated / shows up in the phpinfo view (modes_dir & algorithms_dir both use the default path so no need to uncomment those lines)

    cheers
    w

  • […] Since the version of PHP that comes with Snow Leopard may be missing some of your favorite extensions, here’s a link to some instructions on how to include them (untested by me): Making Snow Leopard’s PHP 5.3.0 usable in the real world […]

  • k00k says:

    If you’re looking at this blog post, you should also take a look at this one which outlines how to tack on mcrypt without a php recompile. It worked for me.

    http://tinyurl.com/yc3jbh2

  • adam says:

    Good catch. Thanks for the additional link.

  • Bryan says:

    I am running into some problems. I really hope someone can help me out. Here are my details:

    OS: Snow Leopard Server 10.6.4
    PHP (Came /w OSX): 5.3.2

    I downloaded libmcrypt (libmcrypt-2.5.8.tar.gz) and installed per the instructions above. I downloaded the source for PHP 5.3.2 (php-5.3.2.tar.gz); however, it was missing the “mhash” directory. So I downloaded mhash (mhash-0.9.9.9.tar.gz) and put it in the php source folder. This was missing “config.m4”, so, I copied it over from the “php.5.2.13.tar.gz” and put it in. That resolved the phpize problem.

    Now, I am receiving the following error when trying to ./ configure mhash and do not know where to go from here:
    configure: error: Please reinstall libmhash – I cannot find mhash.h

    After reading the thread, I tried installing using “php.5.2.13.tar.gz”. I still end up at the “configure: error: Please reinstall libmhash – I cannot find mhash.h” error when trying to ./configure mhash.

    Again, I sincerely appreciate any help anyone can provide.

    Thank you!

  • Bryan says:

    I found a good tutorial; this worked for me:

    mkdir -p /SourceCache

    cd /SourceCache

    curl -O http://surfnet.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

    tar xzf libmcrypt-2.5.8.tar.gz

    cd libmcrypt-2.5.8

    MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure –disable-dependency-tracking

    make

    make install

    —(Now build dynamically loaded extension)—

    cd /SourceCache

    curl -O http://www.opensource.apple.com/source/apache_mod_php/apache_mod_php-44.2/php-5.2.8.tar.bz2

    tar xjf php-5.2.8.tar.bz2

    cd /SourceCache/php-5.2.8/ext/mcrypt

    phpize

    MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure

    make

    make install

    When done, edit/create /etc/php.ini and add:
    extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

    next issue:
    sudo apachectl graceful

  • Sam Moffatt says:

    The reason that mhash isn’t in the PHP 5.3 tarballs is because the functionality offered from mhash is now provided via the hash extension. This means that you only need to install libmcrypt and then the PHP mcrypt extension.

    See: http://php.net/manual/en/mhash.installation.php

  • adam says:

    Thanks for the tip, Sam. I’ll add a note to the article for people to check out your comment.