Installing PHP’s OAuth PECL extension on Mac OS X Snow Leopard

I recently reinstalled the operating system on my Macbook and this time around I decided to use homebrew to manage packages. Since php comes pre-installed with OS X and homebrew encourages using the pre-installed binaries, I have been using the built-in install of php, and so far so good.

But today I tried to install php’s OAuth extension, which comes as a pecl package, and I run into some errors

Before I started I updated the default pecl channel and upgraded pecl extensions already installed:

$ sudo pecl channel-update pecl.php.net
$ sudo pecl upgrade

At this point everything looked good, so I went ahead trying to install the OAuth extension but run into the following error:

$ sudo pecl install oauth

downloading oauth-1.1.0.tgz ...
Starting to download oauth-1.1.0.tgz (44,731 bytes)
............done: 44,731 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
building in /var/tmp/pear-build-root/oauth-1.1.0
running: /private/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/temp/oauth/configure
checking for grep that handles long lines and -e... /usr/bin/grep

...

In file included from /private/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/temp/oauth/php_oauth.h:47,
             from /private/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/temp/oauth/oauth.c:14:
/usr/include/php/ext/pcre/php_pcre.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:44: error: expected specifier-qualifier-list before ‘pcre’
make: *** [oauth.lo] Error 1
ERROR: `make' failed

Hmmm. So something was wrong with the built-in PCRE package. After “googling” the problem and reading many contradicting solutions the only thing that was clear is that I needed a newer version of PCRE. So I installed PCRE using homebrew with the following command (this should also work using any other method – macports, compile from source, …):

$ brew install pcre

This worked fine. So now I tried to install the OAuth extension once again using the same comand as before:

$ sudo pecl install oauth

And this time the extension was insatlled ok, yay!!

The only thing I needed to do after that was adding the extension in my php.ini fie (by default it is in /etc/php.ini). Before the end of the php.ini file add extension=oauth.so. Finally we can check if the extension is getting loaded:

$ php -i | grep -i oauth

OAuth
OAuth support => enabled
source version => $Id: oauth.c 308061 2011-02-06 17:15:34Z jawed $

Note that you will need to restart the apache web server in order for the extension to be loaded in the web server.

Categories: Uncategorized
  • Oldest Modus

    I have the exact samething, except:?
    [root@fw oauth-1.1.0]# php -i | grep -i oauth
    /etc/php.d/oauth.ini,
    OAuth
    OAuth support => enabled
    source version => $Id: oauth.c 308061 2011-02-06 17:15:34Z jawed $
    PWD => /root/oauth-1.1.0
    _SERVER[“PWD”] => /root/oauth-1.1.0
    _ENV[“PWD”] => /root/oauth-1.1.0

    and phpinfo.php keeps telling me that the version corresonding to the file above is:
    OAuth
    OAuth supportenabledPLAINTEXT supportenabledRSA-SHA1 supportenabledHMAC-SHA1 supportenabledRequest engine supportphp_streams, curlsource version$Id: oauth.c 308061 2011-02-06 17:15:34Z jawed $version1.0-dev
    so I guess it’s allright, but this looks kind of awkward to me..

    • lupomontero

      Hmmm, if the OAuth extension is showing up both in the command line and web server I think it should be fine. The reason why the other lines with the path to ?/root/oauth-1.1.0 show up in the output of the command is because ‘grep’ is matching all lines that contain the string ‘oauth’ (case insensitive) and those lines include the string as part of the path (nothing to do with the OAuth extension).

  • holydevil

    Step # 3 from here did the trick for me ?-?http://lifeofadev.com/2011/03/09/mac-os-x-pcre-h-no-such-file-or-directory/

    sudo cp /opt/local/include/pcre.h /usr/include/

    • lupomontero

      Did you install pcre using homebrew or MacPorts?

      • holydevil

        Macports

        • lupomontero

          I guess MacPorts installs everything under /opt/local whereas homebrew uses /usr/local and the headers from /usr/local/include get picked up.

  • This helped, thank you. Most sensible blog post on the issue I’ve been able to find.

  • Thanks for the awe-sauce advice — clear and concise!

  • Post1box

    in my case the install was successful, but the php command does show oAuth. It seems that the oauth.so is not loading even though the build process completed successfully and the extension oauth is enabled in the php.ini file. Can you help advise what is the problem, I am using Max OS 10.5 and MAMP

    • Post1box

      typo in my previous post. here is the corrected one …?in my case the install was successful, but the php command NOT does show oAuth. It seems that theoauth.so?is not loading even though the build process completed successfully and the extension oauth is enabled in the php.ini file. Can you help advise what is the problem, I am using Max OS 10.5 and MAMP

      • lupomontero

        If you are using MAMP make sure that you are running the pecl and php commands provided by MAMP and not the built in ones. You can try ‘which php’ and ‘which pecl’ to see what executables you are running. You might want to prepend the path to the MAMP executables to your shell’s PATH to make sure you always run the right ones.

  • Gtfisher

    This was an EXCELLENT walkthrough — thank you, I was really stuck on this.? Your directions worked perfectly.

  • I found this solution the best, I am running XAMPP and was trying to get oAuth installed correctly.
    sudo /Applications/XAMPP/xamppfiles/bin/pecl install oauth

    I was able to install homebrew without a problem but pecl could not be found on my system after installing pcre with homebrew.-bash: pecl: command not found

  • Thank you.

    Instructions are good for OS X Lion (10.7.3) as well.

  • Cal

    thanks so much!

  • Yangxinyi

    you are my hero!!!!

  • nan

    brew install php54-oauth

    done.

  • Muhammad Asif

    a complete and sample installation for Oauth for the begginers? plxxxx

  • Pingback: Install PHP OAuth Extension In Snow Leopard - Just just easy answers()

  • Jubayer Arefin

    Thanks man. Just installed successfully on OSX Yosemite (10.10.4)

  • adjwilli

    Thanks for this tutorial. The PHP and PECL documentation really needs to have info like this readily available. Also, that last bit about the php.ini was a bit tricky since I skimmed over it the first time.