Activating SSH support in MacPorts PHP
[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:
- Start by installing libssh2 via MacPorts using the command:
sudo port install libssh2
- 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.
triggered the following error (since ssh2 is apparently beta),pecl download ssh2
so I usedFailed 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
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 librarypecl download channel://pecl.php.net/ssh2-0.11.0
The final command informed me the ssh2.so library was placed intar xzvf ssh2-0.11.0.tgz cd ssh2-0.11.0 phpize ./configure --with-ssh2=/opt/local make sudo make install
/opt/local/lib/php/extensions/no-debug-non-zts-20060613/ - Now you need to make sure PHP loads the new module, so we open the PHP configuration file
/opt/local/etc/php.iniand edit the extension_dir line to point the extension directory above:
and then add the following line to the end of the section on “Dynamic Extensions”:extension_dir = "/opt/local/lib/php/extensions/no-debug-non-zts-20060613/"
If you edited everything properly, a simpleextension=ssh2.so
php -vfrom the command line should NOT trigger any errors. - Finally, I restart the apache2 server so that the reconfigured PHP is loaded using
At this point, I checked (via thesudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart
phpinfo();command to see if the web server was supporting SSH. Near the bottom of thephpinfo();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. - 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.

-
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.inifile or the extensions directory where I installed ssh2.

