SSH2 extension activation in PHP 5.3.0 0
This is an upgraded tutorial to getting SSH2 support under PHP 5.3.0 that I wrote a while back. Getting SSH2 support in PHP is useful for maintaining WordPress blogs. It would be nice if such an extension were not necessary, but this is the only way WordPress supports SSH administration through their web interface.
The big difference is that I will now be using the built-in Apache2 and PHP 5.3.0 under MacOS 10.6.1. I have gotten tired of the fact that everytime MacPorts updates it PHP installation, it tends to clobber the php.ini file for the site, requiring me to re-setup everything. Furthermore, I am also a bit tired of having MacPorts install its own version of everything I already have under MacOS X (such as Apache2, PHP, and MySQL). I understand their philosophy (and the practicality of it), but I am trying to keep my computer as clean as possible. As such, I am only using MacPorts to provide libssh2 to the SSH2 extension for PHP.
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:
- If you haven’t already, start by installing libssh2 via MacPorts using the command:
sudo port install libssh2
- Download the necessary SSH2 PHP extension using the build in PECL command
sudo pecl download channel://pecl.php.net/ssh2-0.11.0
Thesudois necessary because a lock file needs to be created during the download in/usr/lib/php, which is a protected directory. However, the file is downloaded to the current directory. Once the download is complete, we will need to unpack the SSH2 extension and go into its directory:
If you try to do the normaltar xzvf ssh2-0.11.0.tgz cd ssh2-0.11.0
phpize/configure/makesequence for compiling PHP extensions at this point, you will get a string of error messages ending with something like
/private/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/download/ssh2-0.11.0/ssh2.c:1105: warning: passing argument 4 of 'add_assoc_stringl_ex' discards qualifiers from pointer target type
This is occuring because there is an incompatibility between this ssh2 extension code and PHP 5.3.0. It can be patched by downloading the ssh2-php53.patch file from http://remi.fedorapeople.org/ssh2-php53.patch and applying the patch from the command line in the ssh2-0.11.0 directory
Once you have done that, you can finish the SSH2 PHP extension compilation usingcurl -o ssh2-php53.patch http://remi.fedorapeople.org/ssh2-php53.patch patch < ssh2-patch53.patch
The final command informed me the ssh2.so library was placed inphpize ./configure --with-ssh2=/opt/local make sudo make install
/usr/lib/php/extensions/no-debug-non-zts-20090626/ - Now you need to make sure PHP loads the new module, so we open the PHP configuration file
/etc/php.iniand edit the extension_dir line to point the extension directory above:
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626/"
and then add the following line to the end of the section on “Dynamic Extensions”:
extension=ssh2.so
If you edited everything properly, a simplephp -vfrom the command line should NOT trigger any errors. - Finally, I restart the apache2 server so that the reconfigured PHP is loaded using
sudo apachectl restart
At this point, I checked (via thephpinfo();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.


