Wordpress. Updating the core and plugins over SSH
Suppose we have a blog http://example.org/ and need to periodically update its plugins and the Wordpress core itself.
The trouble is that only FTP is supported by default, and I don’t have it. The only option available to me is SSH, so that’s what we’ll add!
Setup
Let’s edit our “wp-config.php” configuration file:
$project_root = dirname(__file__);
/*
FS_METHOD forces the filesystem method. It should only be "direct", "ssh", "ftpext", or "ftpsockets".
Generally, You should only change this if you are experiencing update problems, If you change it, and
it doesnt help change it back/remove it, Under most circumstances, setting it to 'ftpsockets' will
work if the automatically chosen method does not.
See: http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants
*/
define('FS_METHOD', 'direct');
define('FTP_BASE', $project_root);
define('FTP_CONTENT_DIR', $project_root . '/wp-content/');
define('FTP_PLUGIN_DIR ', $project_root . '/wp-content/plugins/');
define('FTP_PUBKEY', '/home/example_user/.ssh/id_rsa.pub');
define('FTP_PRIKEY', '/home/example_user/.ssh/id_rsa');
define('FTP_USER', 'example_user');
// define('FTP_PASS', 'password');
define('FTP_HOST', '127.0.0.1:22');
Here, “example_user” is the username under which the connection will be made.
Now we need to generate keys (of course, we could use “password” instead, but I don’t like that solution) and set up our .ssh:
ssh-keygen
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
chmod -R 644 .
chmod 755 .
Let’s test the connection from the server (i.e., connecting to itself):
ssh example_user@127.0.0.1 -p 22
If it doesn’t connect, we need to edit “/etc/ssh/sshd_config” and uncomment or add:
ListenAddress 127.0.0.1
If the ssh2 extension for PHP isn’t installed, you can download it and install it manually http://pecl.php.net/package/ssh2, or install it from ports if you’re running FreeBSD:
cd /usr/ports/security/pecl-ssh2
make install clean
Usage
Go to the Wordpress admin panel, to “Wordpress Updates”->“Update Automatically” (“http://example.org/wp-admin/update-core.php?action=do-core-upgrade"), and update everything we need.
If your connection drops during an update (as mine did), increase the timeouts for your web server.
If you’re using Nginx, set the appropriate proxy_read_timeout or fastcgi_read_timeout.
P.S. Inspired by http://kbeezie.com/view/wordpress-autoupdate-ssh/
Comments are closed. Read the original discussion in Russian →
