00

How To: Manually Repair or Upgrade WordPress via SSH

wordpress-logo

Recently I inherited a dated – and severely damaged – installation of the WordPress CMS/blogging platform.  Because of the age of the installation and the fact that the previous owner neglected to maintain it, I came to the conclusion that I would simply be better off to completely reload the WordPress core; the actual “application”, if you will – all whist keeping the data from uploads and addons.

Knowing that the WordPress administration console allowed for this to be done rather easily, I figured that such a task would only take a couple of clicks to be home free.  However, as soon as I navigated to the “/wp-admin” directory from my web browser, I found that that too was damaged.  With this in mind, I initially pondered downloading a copy of the latest WordPress version onto my local computer, manually adding the content to it, and re-uploading.  However, having shell (SSH) access to the server that the site was hosted on, I was able to come up with a much more efficient method of re-loading the WordPress core files.

After connecting via SSH (using the username that the installation belonged to), I navigated to the “home” directory that among other things held the site.

cd ~

From there, I used the “wget” command to download a bare copy of the most recent WordPress version onto the server.  Note that the “latest.tar.gz” file in this example will always contain the most recent version of WordPress, so there should be no worry about this post becoming out of date.

wget http://wordpress.org/latest.tar.gz

After downloading the file, I had to un-tar it in order to use its contents.

tar -xvf latest.tar.gz

This created a “wordpress” folder in the home directory, which is represented as “~/wordpress”.  Now, the final task was to apply the clean core to the existing site, which for the sake of this post we will assume to be “~/sites/mywebsite.com”.

cp -rf ~/wordpress/* ~/sites/mywebsite.com

In plain English, this statement means “copy the contents of the recently downloaded WordPress core into the existing website directory, over-writing any existing files.”  Because the bare WordPress core does not contain any content or configuration files, it will not over-write these respective files in your existing site.  When all is said and done, this allows for you to manually upgrade and repair an existing WordPress site.

Even though this method does not over-write and remove any third-party themes, addons, or content and does not touch the MySQL database in any  way shape or form, I would still recommend making a backup copy of the WordPress site before you do anything; especially if you are unfamiliar with the Linux command-line or have not personally tested this method on your own.

It is also important to note that this method will over-write the current installation of WordPress with the latest version. In some cases this may cause a number of issues with existing addons/plugins and themes that are not compatible with the latest WordPress version. With this in mind, you should be very cautious and do some research on your configuration and compatibility before making these changes.