Recently, I am in need to use SFTP on one of my PHP script. Fortunately, PHP does support it through SSH2 binding. Unfortunately, however, MAMP doesn’t come with SSH2 extension. So it looks like I have to recompile myself.
Adding SSH2 extension to your MAMP the easy way
I’ve compiled SSH2 extension for Mac. Note that it was compiled on Intel Mac on 10.5.6 Leopard and was tested only on my Intel MacBook Pro, so your mileage may vary. Download it by following this link : MacOS X SSH2 PHP Extension Binary.
If you’re using MAMP
- Save the file to /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922 or other directory specified in phpinfo page extension_dir.
- Edit php.ini My php.ini is /Applications/MAMP/conf/php5/php.ini. yours may vary. Do consult phpinfo page again for the location of php.ini. Find the location on the file where the extensions are defined. Add a new line containing “extension=ssh2.so” (without quotes).
- Restart your MAMP server and navigate to phpinfo page. Search for ssh2. If everything works well, you should see it like my screenshot below.

If your’e using the built-in PHP with MacOS X
The steps is basically the same. The only difference is where to save the file. On mine, the extension_dir is under /usr/lib/php/extensions/no-debug-non-zts-20060613 and PHP.ini is on /etc/php.ini. You can then restart your server from terminal using apachectl restart or by going to System Preferences -> Sharing. Then uncheck Web Sharing and check it again.
Adding SSH2 extension to your MAMP the hard(er) way
Well, if my binary above doesn’t work for you, then you may have to compile SSH2 extension yourself. Please look over my other article Rebuilding MAMP stack from scratch. to make sure you have all the prerequisites. Assuming that you do,
- Download libssh2 from sourceforge.
- Then untar the file and compile it.
user:compile$ tar -xf libssh2-1.2.1.tar user:compile$ cd libssh2-1.2.1 user:libssh2-1.2.1$ ./configure user:libssh2-1.2.1$ make user:libssh2-1.2.1$ sudo make install Password:
- Download SSH2 PECL source code.
- Then untar and compile it.
user:compile$ tar -xf ssh2-0.11.0.tar user:compile$ cd ssh2-0.11.0 user:ssh2-0.11.0$ phpize user:ssh2-0.11.0$ ./configure user:ssh2-0.11.0$ make
- Once you successfully compile, you should have ssh2.so under modules/ directory. At this point, you can simply copy the file to the appropriate location of your PHP (or you can follow the same instructions above for either MAMP or the built-in PHP).
That’s about it … I hope that this article helps you in enabling ssh2 extension for PHP on your MacOS X. And as always, I welcome comments / suggestions / questions. I’m looking forward to improving my solution with your comments / suggestions / questions.






