WordPress Auto-update via SFTP on a non-standard port
Assumptions: You have WordPress up and running on Debian-5 “Lenny” (Stable).
WordPress has a nifty “auto-update” feature built-in that works via FTP or SFTP. However Updating via FTP is a horrible idea because FTP transmits usernames and passwords IN PLAIN TEXT!. In general the use of FTP should be avoided.
So updating WordPress via SFTP sounds wonderful but I ran into a couple of wrinkles in getting this to work:
* I run SSH (SFTP) on a non-standard port. The default port for SSH is port 22 but I run on a non-standard port, moreover Wordpress hardwires the port used (22) for SFTP
* You have to enable PHP to make SSH connections. In specific what’s needed is the PHP extension that provides the bindings to the functions of libssh2 (which implements the SSH2 protocol).
Step 1. First we tackle the problem of getting WordPress’ SFTP function to work on a non-standard
The sftp port setting that WordPress uses is in the ”class-wp-filesystem-ssh2.php” file. On my server it’s located at:
On line 67 of the “class-wp-filesystem-ssh2.php” file, you’ll find this code:
$this->options['port'] = 22;
Change this to the (non-standard) port you’re using for SSH. For example, it should look something like this:
$this->options['port'] = 20022;
Important! This file would most likely get updated when WordPress gets updated, so your port setting will get changed back to the default 22. So after each update you’ll want to check the port setting in this file.
I’d like to see WordPress place the SFTP port setting in the ”wp-config.php” file so that subsequent updates won’t revert this setting.
Step 2. Next we install the PHP extension for SSH2.
We need to install the packages necessary to build and install the extension. As root:
#aptitude install build-essential php5-dev php-pear libssh2-1-dev
Force-install (-f) the SSH2 PECL package:
#pecl install -f ssh2
Instruct PHP to load the newly installed extension:
#echo “extension=ssh2.so” >> /etc/php5/conf.d/ssh2.ini
And that’s it. You should WordPress auto-updating via non-standard SSH port should work now. When you update you should see this [wordpress-autoupdate-via-sftp.jpg].
Running SSH on a non-standard port: