Quick Tip: Upgrade Your WordPress Site via SSH

I have already written about how to install WordPress via the shell. I am taking it further today by showing how you can upgrade it as well using shell access. Though you can always upgrade from within WordPress using the 1-click method, the shell method is more secure as it encrypts all the data transfer. There are two ways of doing it: You can do it using an SSH client or enable WordPress to use SSH Transfers for all types of upgrades whether its a core upgrade or plugin/theme upgrade/installs. I will discuss both methods here.


Method 1 Upgrading Using an SSH Client

Important Note: Always ensure you do a complete backup of your WordPress install's files and database before performing an upgrade.

Now I won't write again about how to connect to SSH as I have already discussed that in my previous tutorial. Now all the commands here are being done assuming that you are in your blog's directory(blogdemo in this case). First of all download the latest version of WordPress and extract it.

Now we need to delete the old wp-admin and wp-includes directories.

Now go to the wordpress directory where we extracted the latest WordPress files and move them back to the blogdemo directory.

You will be asked to overwrite certain files and some directories as well inside wp-content. Just press y and proceed. Now exit from the wordpress directory and delete the directory and the file latest.tar.gz. We're done with them now, and don't need them taking up space.

In the final step just login to your dashboard and run the database upgrade.


Method 2 Enabling SSH2 for WordPress Upgrade/Installs

Did I mention... Always ensure you do a complete backup of your WordPress install's files and database before performing an upgrade.

In this method, you can enable WordPress to use SSH for upgrading and plugin/theme installations. First of all you need to check with your webhost if they have the SSH2 extension installed for PHP or not. To check for that run the following PHP command

If this command returns true, that means it's installed, otherwise it's not. If your webhost doesn't offer it, ask them to install it for you or if you are running a VPS/dedicated, you can install it yourself. Follow the method to install from here.

First of all we need to generate a working set of public and private keys which will be used for authenticating the user. To do that, use the following command in your SSH client:

You will be asked for the name of the file. You can leave it blank or enter any custom name. If you leave it blank, the file names will be id_rsa.pub and id_rsa. Also you can set a passphrase to add additional security or can leave it blank.

Time to add keys needed to be added to the authorized_keys file. In our case, SSH keys were generated and kept in the .ssh directory in the root directory.

Now change permissions so that WordPress can access those keys.

You may need to change the user of the directory if you are running PHP as a different user.

Now that you have got SSH2 setup and working, you should see the following screen while performing any upgrade/plugin or theme install.

Here user is the SSH username you used to login and perform all the commands and password is the passphrase you were asked to set during the ssh-keygen command. If you didn't choose any passphrase, you should keep the password field blank. To avoid entering this data repeatedly, enter the following code in your wp-config.php

From now on WordPress will perform all file transfer operations using SSH.


References

Tags:

Comments

Related Articles