How to enable PECL uploadprogress extention in MAMP

By webmaster, 16 juli, 2010
Image
PECL and MAMP

26.07.2010: Updated and improved to make it compatible with MAMP ver. 1.9. If you are not a PECL auto make ninja, please resort to the manual build if PECL modules chapter, then it give you more fine grain control of the build process it self.

Uploadprogress or simply any PECL/PEAR module in MAMP

This howto will show you how to get those pesky PECL modules to compile in MAMP like uploadprogress or Xdebug. First a little Drupal background information. FileField and ImageField 3.0 for Drupal 6 released as one of many new features enables us to use the PHP extension uploadprogress that especially come in handy giving the user feedback of progress when uploading large files. Many OS X users are using MAMP to sandbox their development environment but compiling a PECL/PEAR module is not quite that easy in MAMP.

Content

Build uploadprogress in Leopard (version 10.5.x)
Build uploadprogress in Snow Leopard (version 10.6.x)
Manually build uploadprogress or any PECL extension out there.
Trouble shooting and links to prebuild modules and some word of warning.

When installing the Drupal module filefield-6.x-3.x you will in /admin/reports/status find a friendly warning telling you that the uploadprogress module is a nice addon.
Upload progress
Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the PECL uploadprogress library (prefered) or to install APC.

As an early adopter I could not find any information on the web on how to compile and get a PECL PHP extension compiled and up and running under MAMP. After a day forth and back between pages I solved it, and decided to try and document is for other that are still struggling.



Leopard (10.5.x)

apple_mac_os_x_10.5_leopard_1024x768_1.jpg

  1. Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
  2. Download the complete PHP source code from php.net into /Applications/MAMP/bin/php5.2
  3. Create an include directory in the the php5.2 directory.
  4. Unzip/tar the php source archive and move it to /Applications/MAMP/bin/php5.2/include
  5. Rename the php source directory to just php (so then it will look like /Applications/MAMP/bin/php5.2/include/php)
  6. In Terminal use the following commands to compile the extension:

    cd /Applications/MAMP/bin/php5.2/include/php
    ./configure
    cd /Applications/MAMP/bin/php5.2/bin

    In MAMP 1.9.x and newer (I guess) the utilities in this directory are not executable (probably is this a safety proaction) make all these files executable, either by using Finder or from shell with:

    sudo chmod a+x *

    All the files in the directory should now be executable and you are all set to compile the extension:
    sudo ./pecl i uploadprogress
  7. The result should be "Build process completed successfully". Now all you need is to move the newly compiled extension to the folder containing the existing PHP-extensions. On my system is it located at: /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922 it might be slightly different on your configuration.

    To help with finding the extensions directory, look at your phpinfo page from MAMP: Under "PHP Core" is the listing for "extension_dir" that will be the path you want to copy to. You can also use this same page to confirm that the extension is successfully enabled.

  8. Open the /Applications/MAMP/conf/php5.2/php.ini file and add extension=uploadprogress.so in the ; Extensions section.
  9. Restart MAMP and you should be all set.

To verify that the extension got successfully loaded by Apache, take a look in your phpinfo page from MAMP. Just search the page for "uploadprogress".
Screen shot 2009-09-20 at 13.40.22.png

You can also manually start PHP from your command shell and ask what extensions it loaded:/Applications/MAMP/bin/php5.2/bin/php -m



Snow Leopard (10.6.x)

snow-leopard1.jpg

    Testet and updated to work with:

  • MAMP 1.9
  • PHP 5.2.14
  • OS X 10.6.4
  • Xcode: 3.2.2

Snow Leopard is almost identical to Leopard (and should be). A lot of people had problem loading the module they compiled (read comments bellow) on Snow Leopard. Snow Leopard introduced proper 64 bit support and Xcode compiled the module in 64bits mode only though MAMP 1.8/1.9 is still a 32bit (i386) application and loading a 64bit extension into a 32bit application is doomed. This is what worked on my system:

  1. Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
  2. Download PHP 5.2.x complete source code from php.net.
  3. Create an include directory in your MAMP php5.2 directory
    mkdir /Applications/MAMP/bin/php5.2/include
  4. Unzip/tar the php source archive into the newly created include directory and rename php-5.2.xx to php so your directory should read: /Applications/MAMP/bin/php5.2/include/php
  5. Then to:
    cd /Applications/MAMP/bin/php5.2/include/php
    ./configure
  6. Before starting to compile do we need to do some GCC environment definitions, so paste this into your terminal:
    MACOSX_DEPLOYMENT_TARGET=10.6
    CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
    CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
    CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
    LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
    export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
  7. use the following commands to compile the extension:
    cd /Applications/MAMP/bin/php5.2/bin
    In MAMP 1.9.x and newer (I guess) the utilities in this directory are not executable (probably is this a safety proaction) make all these files executable, either by using Finder or from shell with:
    sudo chmod a+x *

    All the files in the directory should now be executable and you are all set to compile the extension:
    sudo ./pecl install uploadprogress
    The result of from this command could in the end of log file read something like:
    Build process completed successfully
    Installing '/usr/lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so'
    install ok: channel://pecl.php.net/uploadprogress-1.0.1
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=uploadprogress.so" to php.ini
  8. If the build process completed successfully all you need is to copy the newly compiled extension to the folder containing the already existing MAMP PHP extension but where do you copy your newly compiled extension? To locate the directory look in your MAMP phpinfo page, search for "extension_dir" and you will find the path in used on your system or from command shell:
    grep "extension_dir =" /Applications/MAMP/conf/php5.2/php.ini
    On my system was it located at /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/ it might be slightly different on your system, anyway on using my paths:
    cp /usr/lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/
  9. With the extension safely located in the correct directory it is time to enable it. Open MAMP php.ini file (NOT the system global php.ini file that belongs to OS X) located at:
    /Applications/MAMP/conf/php5.2/php.ini
    and add
    extension=uploadprogress.so
    to the "Dynamic Extensions" sectioni.
  10. Restart MAMP and you should be all set.

To verify that the extension got successfully loaded by Apache, take a look in your phpinfo page from MAMP. Just search the page for "uploadprogress".
Screen shot 2009-09-20 at 13.40.22.png

You can also manually start PHP from your command shell and ask what extensions it loaded: /Applications/MAMP/bin/php5.2/bin/php -m



Manually build your PECL extension

152833988_dcba4bacd9.jpg

    Testet and updated to work with:

  • MAMP 1.9
  • PHP 5.2.14
  • OS X 10.6.4
  • Xcode: 3.2.2

No you don't need to be a Ninja to manually build an PECL module it normally involve a few more steps building the extension and be be very handy on computers with multiple PHP installations then makes it easier to control how to make the build and from where to include stuff.

  1. Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
  2. Download PHP 5.2.x complete source code from php.net.
  3. Create an include directory in your MAMP php5.2 directory
    mkdir /Applications/MAMP/bin/php5.2/include
  4. Unzip/tar the php source archive into the newly created include directory and rename php-5.2.xx to php so your directory path should read: /Applications/MAMP/bin/php5.2/include/php
  5. Then do:
    cd /Applications/MAMP/bin/php5.2/include/php
    ./configure
  6. Download the PECL extension (normally pecl download uploadprogress will do the trick) and unpack it to you favourite directory and set up the GCC environment definitions to make sure we also get a i386 (32bit) version of the extensions so go ahead and paste the following into your terminal:
    cd uploadprogress-version
    /Applications/MAMP/bin/php5.2/bin/phpize
    MACOSX_DEPLOYMENT_TARGET=10.6
    CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
    CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
    CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
    LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
    export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
    ./configure --with-php-config=/Applications/MAMP/bin/php5.2/bin/php-config
    make
    make install

The compiled module should now get copied to the correct extension directory and all you need to do is to restart the Apache MAMP server.



Still not working or are you just lazy?

3318930880_5344b6af33.jpg

If all of the above fails, read the instruction again and try to understand the steps, follow the carefully and keep a eye out for errors when MAMP is starting Apache. Monitor /Applications/MAMP/logs/php_error.log with Apple Console utility or from shell:
tail -f /Applications/MAMP/logs/php_error.log
You can also try loading more information regarding the extension manually:
/Applications/MAMP/bin/php5.2/bin/php --ri uploadprogress
This should give you something like:
uploadprogress
uploadprogress support => enabled
Version => 1.0.1
Directive => Local Value => Master Value
uploadprogress.file.filename_template => /var/tmp//upt_%s.txt => /var/tmp//upt_%s.txt
uploadprogress.file.contents_template => /var/tmp//upload_contents_%s => /var/tmp//upload_contents_%s
uploadprogress.get_contents => 0 => 0

A lot of the problem people are seeing trying to compile on Snow Leopard is related to PECL auto build are not correctly set up, and the pecl utility are building the extension by using the system wide PHP installation and/or the extension are build for 64bit programs only. MAMP (up to 1.9) are still running in 32 bit mode so loading a 64 bit version of your module in a 32 bits MAMP is futile. Check the compiled module:
file uploadprogress.so
uploadprogress.so: Mach-O universal binary with 2 architectures
uploadprogress.so (for architecture i386): Mach-O bundle i386
uploadprogress.so (for architecture x86_64): Mach-O 64-bit bundle x86_64

Does this this command tell you that it is only build for Mach-O 64-bit bundle x86_64 do you have an error in your PECL/PEAR config. Check for .pecl.default config files in your system that might cause you grief.

Still reading? Then I guess you are getting quite desperate, but not all hope is not lost. I have also provided two precompiled extensions:

  1. uploadprogress.so version 1.0.0 The extension is tested in MAMP 1.7.1, 1.7.2, 1.8.x under OS X version 10.5.x and 10.6.x.
  2. uploadprogress.so version 1.0.1 The extension is tested in MAMP 1.8.x and 1.9 under OS X version 10.6.x.

As usual you need to include the module in php.ini belonging to MAMP and restart the MAMP Apache server

Heads up if you have macports installed

Just a heads up...one thing that can cause headaches is if you have macports libraries installed that you have to link against....on Snow leopard if you don't edit /opt/local/etc/macports/macports.conf and uncomment this line build_arch i386 before you install the port it will compile using x86_64 architecture.....

Then when you try to build your extension (fileinfo in my case which needs libmagic installed) and point the config to look in /opt/local/ , if you are targeting 32 bit the build will crap out, and if you build in 64 bit obviously and you are downloading a precompiled version of 32 bit MAMP, then the extension won't load....anyhoo, I spose you could build MAMP from source in 64 bit as the other alternative.

Credits

This how to is largely build upon http://www.lullabot.com/about/nate-haug excellent article on how to Setup a Memcached-Enabled MAMP Sandbox Environment