Ramblings on technology with a dash of social commentary
RSS icon Email icon Home icon
  • Enabling Command-line PHP Curl on Mac OS X Lion

    Posted on October 25th, 2011 phpguru No comments

    If you’re doing web development on the Mac with the Apache 2 and PHP 5.3.6 that ships from Apple, you might one day run into a use for some command-line scripts. I happen to be doing just that at the moment. Well it seems that Apple ships PHP 5 with everything you need to use the curl libraries, except the extension.

    I was surprised with an error warning like this:

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_curl.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_curl.dll, 9): image not found in Unknown on line 0
    Huh? I need a Windows DLL on Lion? I guess so…

    I’ve been using CURL scripts from PHP running under Apache since day one, but what I’m realizing is that the command line version of PHP, aka, the php-cli, is installed a little differently.

    First, you may want to check your php.ini that the extension is uncommented (remove the preceding semicolon):
    extension=php_curl.dll This is a pretty obvious step to try, even though Lion is clearly not Windows, and the section in php.ini clearly says it’s for Windows Extensions.

    So you might try installing the latest version of cURL.
    cd ~
    mkdir src
    cd src
    curl -V
    curl 7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5

    At this point, you start wondering what’s going on, because cURL is installed at the Factory by Apple. Strange…

    So you can
    sudo find / -name php_curl -print just to see if the DLL is in the wrong place or something, maybe a quick symlink would fix it.

    But this is interesting… PHP 5.3.6 from Apple ships with the curl extension:

    cd /Users/%me%/Documents/src/php-5.3.6/ext/curl
    sudo make install

    Now edit your php.ini and add
    sudo apachectl restart
    Well that didn’t do much. Now I get:
    PHP Warning: Module 'curl' already loaded in Unknown on line 0

    Hmmm, stranger still.

    Here’s the punchline: All you need to do is comment out (add the semicolon at the front)
    and restart Apache.

    The warning was exactly correct – it couldn’t find a Windows DLL. I wonder why that’s uncommented.

    I don’t remember uncommenting it, but maybe I did.

    Leave a reply