MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness)

Install the PECL SSH2 extension to MAMP PRO and the PHP CLI in OSX.

Or madness in general. So as you may know, I’ve started using PHPStorm to work locally. I decided to dust off an old SSH2 wrapper I wrote and play with how PHPStorm uses PHPUnit and does refactoring. I knew that I would have to install the extension via PECL and was like, “Oh it can’t be that bad to do it through MAMP PRO” and as you may have guessed, I sealed my own fate for a couple hours. One thing I can say is that, even though I use a convenient app like MAMP PRO to set up my local development environment, I’m glad my sysadmin-fu is up to snuff enough to fly without the conveniences because after this ordeal, I feel like I might as well have made my MAMP stack from scratch with all the hoops I jumped tonight. (I’m pretty sure that last sentence is also one of the worst run-on sentences ever).

The first thing you need to know is that the PECL command is located at the directory


when I tried to run

sudo ./pecl install -a ssh2 channel://

from that directory, I got the error:

Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050
PHP Notice: unserialize(): Error at offset 267 of 1133 bytes in /Applications/MAMP/bin/php/php5.3.6/lib/php/PEAR/Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

I found out later that the error is most likely caused by the file


So if you get an error, try doing

sudo mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bkp

If you’re still getting the error, you can also the following:

  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 into /Applications/MAMP/bin/php/php5.3.6/
  3. Create an include directory in the the php5.3.6 directory.
  4. Unzip/tar the php source archive and move it to/Applications/MAMP/bin/php/php5.3.6/include/
  5. Rename the php source directory to just php (so then it will look like /Applications/MAMP/bin/php/php5.3.6/include/php)
  6. In Terminal use the following commands to compile the extension:
    cd /Applications/MAMP/bin/php/php5.3.6/include/php

That should allow you to run the PECL command however, you will probably get a complaint about not having libssh installed. So you will have to

  1. go download libssh2 ( As much as I like git, I recommend  downloading the latest release tarball instead of cloning the repo. For some reason, I got a version incompatibility error when trying to run the PECL install with the repo version and had to do all these steps over with the tarball release version.
  2. unzip the directory and cd to the upacked directory in the terminal.
  3. run: ./configure; make all install;
    libssh should compile and place the output file in src/*.o
  4. copy all headers from the include folder within the libssh2 directory to
  5. copy all compiled files (*.o) from the src folder within the libssh2
    directory to /usr/local/lib/

After you’ve successfully ran the the PECL install, it should tell you to  Add the line

to the Dynamic Extensions area of your php.ini file. I believe both MAMP and MAMP PRO allow you to edit the necessary ini through File>Edit Template.

MAMP edit php.ini


Lastly, restart apache. You should be able to see the SSH2 extension when you load a phpinfo() page.

Bonus round:

I’m not sure how I have  PHP CLI working in OSX but if you’ve followed the steps above and try to verify the extension install with through the cli, it won’t show up.

$ php -a
php> phpinfo();

This is because (if you’re also using MAMP PRO) the binaries are different. The good news is that you can make things happy in 3 easy steps

  1. run `sudo ln -s /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ /usr/lib/php/extensions/no-debug-non-zts-20090626/` in the terminal.
  2.  Edit the /etc/php.ini (copy /etc/php.ini.default if /etc/php.ini doesn’t exist)  like you did for the MAMP php.ini(s)
  3. profit.

Note: I still have to install PHPUnit into my current setup so that may or may not elicit another blog post.


Enhanced by Zemanta

2 comments on “MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness)Add yours →

  1. Mamp is a great tool when you want to work on a php project with small technicall requirements, such as Drupal or WordPress projects. But when you want to do more complex things, it has just so many limitations and unfixed bugs:

    In my opinion, if you need PECL or if you need to compile php by yourself, Mamp is just not the right tool anymore. It's lame, i like their UI.

    1. For 90% of my use case, MAMP is perfect for my development needs. The limitations are the trade off for not playing sysadmin for projects.

      I do agree that if your needs are complex, you're better off compiling from scratch/playing sysadmin and last night it felt I probably should've did that to start off with. Thanks for the link on more CLI tricks.

      Hopefully the future iterations of MAMP will build in PECL/PEAR support into their product. I don't think I needed to compile PHP to get things to work, I think I just needed to move that file. Since I did those compilations steps first, I have no way of knowing which steps produced the desired effect. I recommended the file moving because after doing the compile steps, I still received the error. Only after moving that file did things work. I have no way of telling if the compilation steps had any influence on that outcome.

Leave a Reply