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:
- 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.
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/
- 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.
- 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.
- 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.ini
file or the extensions directory where I installed ssh2.
Category
Command Line Tricks, MacOS X, MacPorts
Posted on
December 05, 2008 by
Juan
There is a problem with libxml2 from version 2.7.1 onward where it completely deletes any greater than (>) and less than symbols (<) sent to it. This is messing up my blog posting unless I do it within the WordPress interface since attempts to use xmlrpc.php use PHP, which is compiled against libxml2, and thus the posting gets mangled.
The solution suggested on the PHP boards is to compile PHP against expat. This would be kind of a pain for me since I am using the MacPorts install of PHP. So I looked into rolling back to an earlier version of libxml2 using MacPorts. The solution was originally outlined in this blog post by Stephen Chu on how to install earlier versions of ruby under DarwinPorts, I have updated it for MacPorts. The key is to create a local MacPorts repository with the version of the port you want copied over to it.
- First I identified the version of the libxml2 portfile I wanted by going to http://trac.macports.org/browser/trunk/dports/textproc/libxml2/Portfile and entering revisions into the “View revision” box until I found the appropriate version of the Portfile linking to libxml2 2.6.32 instead of 2.7.1. This turned out to be revision 40211 (actually 39551).
- I created a directory to contain my MacPorts repository at
/Users/Shared/dports/ and after creating that directory, I edited the MacPorts configuration file /opt/local/etc/macports/sources.conf to include the line:
file:///Users/Shared/dports
and you should make this line appear before the “rsync” or svn” port listing in the config file, otherwise it defaults to using that version of the port during the install.
- I then installed the old libxml2 port into my local MacPorts respository using subversion:
svn co --revision 40211 http://trac.macports.org/browser/trunk/dports/textproc/libxml2/ textproc/libxml2/
and then I updated the MacPorts index:
portindex /Users/Shared/dports
With this done, I can see the two versions of libxml2 in my ports list, when I issue a
port list libxml2
the result is:
libxml2 @2.7.2 textproc/libxml2 libxml2 @2.6.32 textproc/libxml2
showing the current libxml2 version in MacPorts and the older one in my repository.
- Now I can install the older version of libxml2 by first forcing removal of the current version and then installing the old version:
sudo port -f uninstall libxml2 @2.7.2_1+darwin_9 sudo port install libxml2 @2.6.32
[Warning: Unless you place the file:///Users/Shared/dports line before any rsync/svn lines of the config file noted in step 2, this port install command installs the current version instead of the old version]
- I had to forcible uninstall and then reinstall libxslt but then my reinstall of php within MacPorts went fine. And I can now use WordPress again without any issues when using a remote blog editor.
I just figured in case anyone else wanted to use an older MacPort port they could use this to figure out how.
Category
MacPorts
Posted on
December 05, 2008 by
Juan
FreeType issues under Leopard Resolved: The MacPorts installation of FreeType will now compile a version under Leopard that does NOT throw a
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
error when fonts are used in PHP routines (fuller notes on this problem here although with my “hacked” fix, which is no longer needed). This problem as originally reported under Trouble Ticket #15909 on MacPorts.
Careful with that Apache2 upgrade, Eugene: I also discovered I have to be careful when updating apache2 under MacPorts in that it actually wiped out some of the configuration files stored in /opt/local/apache2/conf/, specifically it overwrote my modified versions of the /opt/local/apache2/conf/extra/httpd-dav.conf file and /opt/local/apache2/conf/extra/http-userdir.conf files. So now I am keeping copies of everything in /opt/local/apache2/conf backed up so I can roll back my changes after an upgrade of apache2 in MacPorts.
Category
MacOS X Annoyances, MacPorts