Bookmark and Share

Adding support for SSH2 on MAMP

Posted: Friday, December 11th, 2009 at 5:04 pmUpdated: Friday, December 11th, 2009 at 5:04 pm

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

  1. 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.
  2. 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).
  3. Restart your MAMP server and navigate to phpinfo page. Search for ssh2. If everything works well, you should see it like my screenshot below.
    MAMP ssh2 Extension.

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,

  1. Download libssh2 from sourceforge.
  2. 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:
    
  3. Download SSH2 PECL source code.
  4. 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
    
  5. 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.

4 Responses to “Adding support for SSH2 on MAMP”

  1. Josh GIlmour Says:

    Nice article, although it looks like you need libssh anyways.

    I tried just importing the .so file with MAMP (php 5.3 didnt work with it, so I had to use 5.2) and apache wouldn’t start… saw the following errors in apache_error_log:
    dyld: NSLinkModule() error
    dyld: Library not loaded: /usr/local/lib/libssh2.1.dylib
    Referenced from: /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/ssh2.so
    Reason: image not found

    * insert sad face here *

  2. Quentin Cotillard Says:

    In order to make it work for me I had to force both the install of libssh2 and ssh2 extension to be 32 bits.

    http://www.libssh2.org/download/libssh2-1.2.8.tar.gz
    user:compile$ tar -xf libssh2-1.2.1.tar
    user:compile$ cd libssh2-1.2.1
    user:libssh2-1.2.1$ ./configure CC=\"gcc -arch i386\" CXX=\"g++ -arch i386\" CFLAGS=\"-O -arch i386\" CPPFLAGS=\"-O -arch i386\" LDFLAGS=\"-arch i386\"
    user:libssh2-1.2.1$ make
    user:libssh2-1.2.1$ sudo make install
    Password:

    http://pecl.php.net/package/ssh2
    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 –with-ssh2 CC=\"gcc -arch i386\" CXX=\"g++ -arch i386\" CFLAGS=\"-O -arch i386\" CPPFLAGS=\"-O -arch i386\" LDFLAGS=\"-arch i386\"
    user:ssh2-0.11.0$ make

  3. Joffrey Jaffeux Says:

    Here is my ssh2.so for php 5.3.6, working with mamp 2 on Lion :

    http://cl.ly/423d3S1n1x17312K1f0u

    If the icon it doesn’t look like a shell try : sudo chmod a+x ssh2.so when you are in the directory of the file.

  4. Justin Marsan Says:

    Little update as some of the information in this post aren’t up to date anymore :

    I tried the “simple” way but it didn’t worked, like the first comment, I didn’t have libssh2 installed. So I went on lissh2.org and downloaded the last version, cd into it, ./configure but still wasn’t working, got the same issue… It’s actually really easy to fix : in the ssh2.so file search for /usr/local/lib/libssh2.1.dylib and replace it by /usr/local/lib/libssh2.1.3.dylib (add .3 basically) and tadaa…

    At least that worked for me and I guess it’ll work for other versions too so if you Mamp doesn’t want to start anymore, and your logs say the file isn’t found, then this should solve it.

Leave a Reply


− 2 = six