Install SSH2 on OSX MAMP PRO

 

Creds http://cyberpunx.com/2011/11/install-ssh2-support-for-mamp-and-php-5-3-x/

Updated instructions 2014

brew update

brew doctor

brew install libssh2
cd /Applications/MAMP/bin/php/php5.4.25/
sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade
sudo pecl install channel://pecl.php.net/ssh2-0.12

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :
 

Build process completed successfully

Installing ‘/usr/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so’

install ok: channel://pecl.php.net/ssh2-0.12

configuration option “php_ini” is not set to php.ini location

You should add “extension=ssh2.so” to php.ini

 

cp /usr/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so

chmod 755 /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so


Edit template, add extension=ssh2.so

restart apache, check for ssh2 with phpinfo mama start page

which php should give you the version of php on osx, if the one you’re using with mamp is not far apart then this method will work, otherwise you will have to compile with php version that matches the one you’re using in mamp

 

How to install ssh2.so for PHP 5.3.x on OSX Lion and MAMP

 

For a recent project I needed to use the ssh2 extension with PHP. I had tried to use phpseclib, but found that it doesn’t support for DSA keys (a requirement for my project). Using the instructions below, you can easily install ssh2 support for PHP using homebrew.

Using homebrew to install libssh2:

brew install libssh2

I was working with a fresh OSX Lion install, so I needed to install pear. Luckily it comes with Lion, so we just need to install and update.

sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade

After pear is setup, we can use pecl to install the ssh2 extension:

sudo pecl install channel://pecl.php.net/ssh2-0.11.3

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :

This next step is optional and should not be done if you already have a /private/etc/php.ini file. However, this step may help others who are working with a fresh install like I was:

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Now we need to add the ssh2.so to the php.ini …so open /private/etc/php.ini with your favorite editor and add the following line:

extension=ssh2.so

After saving, run the following command and it should output ‘ssh2′:

php -m | grep ssh2

Now lets copy ssh2.so to the MAMP extension folder:

cp /usr/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so /Applications/MAMP//bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/

Edit the php.ini template for MAMP’s PHP install and add:

extension=ssh2.so

MAMP PHP Template

Restart MAMP… ssh2 extension should now be installed for the system’s PHP and MAMP’s PHP.

Output of phpinfo(); will show this:

 

Leave a Reply