Urania

A blog named for the muse of Astronomy containing musings by an astronomer

Activating SSH support in MacPorts PHP

Posted on December 11, 2008 by Juan

[I have made an updated version of these instructions for adding the SSH2 PHP extension to the pre-installed PHP 5.3.0 installation on MacOS 10.6 available here.]

I just upgraded the software on this blog to WordPress 2.7. The major new feature I am interested in is automatic upgrading, which could prove quite a time saver. Unfortunately, this automatic upgrading uses only FTP (which is totally insecure) or FTPS (which requires me to set up an SSL certificate).

I noticed that the WordPress code had ssh2 support built-in, so all I need to is activate SSH2 support in the MacPorts installed PHP and I should be able to use SFTP in WordPress to handle the upgrades. I poked around and found this posting outlining the process for adding ssh2 support to Ubuntu. It guided me in developing this list of hints:

  1. Start by installing libssh2 via MacPorts using the command:
    sudo port install libssh2
    
  2. Once it is activated, link the libssh and PHP together using the PECL module SSH2. Unfortunately, directly installing the module with PECL under MacPorts is troublesome, so I just used PECL to download the module.
    pecl download ssh2
    
    triggered the following error (since ssh2 is apparently beta),
    Failed to download pecl/ssh2 within preferred state "stable", latest release is version 0.11.0, stability "beta", use "channel://pecl.php.net/ssh2-0.11.0" to install
    Cannot initialize 'ssh2', invalid or missing package file
    Package "ssh2" is not valid
    download failed
    
    so I used
    pecl download channel://pecl.php.net/ssh2-0.11.0
    
    as suggested and was able to download the PHP library for SSH2. Once the download was complete, I started on the standard compilation sequence for a PHP library
    tar xzvf ssh2-0.11.0.tgz
    cd ssh2-0.11.0
    phpize
    ./configure --with-ssh2=/opt/local
    make
    sudo make install
    
    The final command informed me the ssh2.so library was placed in /opt/local/lib/php/extensions/no-debug-non-zts-20060613/
  3. Now you need to make sure PHP loads the new module, so we open the PHP configuration file /opt/local/etc/php.ini and edit the extension_dir line to point the extension directory above:
    extension_dir = "/opt/local/lib/php/extensions/no-debug-non-zts-20060613/"
    
    and then add the following line to the end of the section on “Dynamic Extensions”:
    extension=ssh2.so
    
    If you edited everything properly, a simple php -v from the command line should NOT trigger any errors.
  4. Finally, I restart the apache2 server so that the reconfigured PHP is loaded using
    sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart
    
    At this point, I checked (via the phpinfo(); command to see if the web server was supporting SSH. Near the bottom of the phpinfo(); listing is a listed of “Registered PHP Streams”. As noted here, it should incude “ssh2.shell”, “ssh2.exec”, “ssh2.tunnel”, “ssh2.scp”, and “ssh2.sftp”. If it does, you have enabled SSH support for Apache2 driven PHP pages under MacPorts.
  5. If you are doing this to get WordPress 2.7 automatic installation working, you will notice now when the automatic installation dialog box pops up, in addition to ftp and ftps, you now have an ssh option.
  6. Now that I got this working, I’ll just have to keep an eye out for any future MacPort updates to PHP and make sure they don’t overwrite the

    /opt/local/etc/php.ini

    file or the extensions directory where I installed ssh2.

6 to “Activating SSH support in MacPorts PHP”

  1. Derak says:
    I am having trouble with this. I am running php entropy (php5-5.2.5-6-beta) on Mac OSX Serve 10.5.8. And I successfully installed libssh2-1.1 and did a pecl -f ssh2 successfully. I go through all the steps without problem, but ssh2 is never activated. ssh2.so gets created and put into "/usr/lib/php/extensions/no-debug-non-zts-20060613/" and my php.ini file has: extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613/" extensions=ssh2.so Here is a php_info() page for everything on my server: http://studentdev.jour.unr.edu/derak/images/rlb/ ssh2 should be showing up in my "Registered PHP Streams" section, but it is not. Any ideas? I feel like I've tried everything here.
  2. Juan Cabanela says:
    This no longer works with MacPorts 1.8 and the new ports structure taken to support PHP 5.3.0. In essence, in the new ports structure used for PHP 5.3.0, all the extensions are supported as separate ports. This means trying to add an additional extension in a separate directory fails. Actually, it looks like the "php5-openssl" port MAY provide the necessary SSH support, but that may be because my old manually installed SSH support is still there. I'll see what I can figure out as time allows.
  3. Derak says:
    Hey Juan, Any more info regarding this? Could the problem be because I am using the entrophy php5.2.5 rather that 5.3.0?
  4. hoursheads says:
    the SSH2 PECL extension is crap. i'd been trying to get it to work for days without success until i found this: http://phpseclib.sourceforge.net/ never did get the PECL extension to work but phpseclib's implementation works wonderfully! shame the wordpress devs don't support it...
  5. Juan says:
    Unfortunately, there does't appear to be an easy way to get WordPress understand phpseclib.
  6. hoursheads says:
    certainly, the WordPress devs are going to have to write new code to accommodate phpseclib, but they had to do that, anyway, for the libssh2 PECL extension.


Leave a Reply


  • Translate

  • Astro Pic o' the Day

  • Archives

  • Admin



↑ Top