WordPress Manual Upgrade for Experts
There so many websites detailing how to manually upgrade a WordPress Site. The vast majority of them seem to be done by people with very little experience with all of the technologies behind WordPress like Linux (CentOS, Ubunto, etc.), PHP, Apache (Nginx, IIS, or other web servers), mySQL (MariaDB, SQL Server, etc.), and others. I mean no offense to them as they are talented in their own right and just trying to help. It did make But it did make me think writing something about a simpler (and safer) way to upgrade a WordPress installation by leveraging more technically adept techniques. So I did.
It also brings up the question, "Why upgrade manually?" For me it was born of a desire to stay within the 4.X.Y series I was using instead of the 5.X.Y version offered. There is a method to change the automatic upgrade method to ignore major version upgrades and only install minor versions (Major#.Medium#.Minor#), but after testing I determined it did not affect the manually triggered upgrade button.
Anyway, onto the detailed steps that leverage the command line and phpMySQL...
BACKUP!
First of all BACK EVERYTHING UP!!! Don't take a chance that the upgrade will mess something up, make a backup. For WordPress, that consists of two items: The website files and the database.
Website Files
Backup the website files by making a copy;
mv WebSiteDirectory WebSiteDirectory.WorkingVersionX.Y.Z
...The original files will then be used to copy into the directory with the upgrade version, covered a few steps later.
The above is the quickest way to preserve a functional version of the website files (the MV command does not change permissions).
The next step isn't necessary, but if you want to make a copy of the website files and test those copies for functionality and peace of mind, use the below command;
cp -ax WebSiteDirectory.WorkingVersion.X.Y.Z WebSiteDirectory
The WebSiteDirectory will need to be erased before copying the new updated WordPress files.
When testing the functionality of the site, it should be completely functional since the above command copies all files and directories (sub-directories too), retains permissions, retains symbolic links, IE makes an exact duplicate.
Database
For the database, use the mySQL (MariaDB, etc.) command line or phpMyAdmin. phpMyAdmin makes it much easier. Select the database in the left pane, Export Tab, "Simple" Radio Button, Go Button, save it to a file, done.
Other Thoughts
Most of the people that have documented how to do a manual upgrade of WordPress also stress the importance of backing up. Their methods won't work if the WordPress upgrade hoses the site for some reason. IE, if one uses a plugin to backup a WordPress site, an upgrade is done which hoses the site, how does one restore a backup with a plugin if the site doesn't work? Bit of an issue there, so instead why not get down to basics and uses some basic commands as explained here. The bottom line is that if one is doing some major stuff like an upgrade, don't rely on a plugin to restore things.
Upgrade
- Download whichever version of WordPress you want: https://wordpress.org/download/releases/
- Extract the files (if downloading a TAR version): tar -xf WhatEverFIleName
- Move or copy the files to the web server directory: mv Source Destination
- Set the proper ownership and file permissions on the new files (the below example is for Apache on CentOS);
chown -R apache:apache /var/www/html/WhatEverDirectory find /var/www/html/WebSiteDirectory -type d -exec chmod 755 {} \; find /var/www/html/WebSiteDirectory -type f -exec chmod 644 {} \;
- Copy the working version of the WordPress website files into the new directory (The below command will not overwrite any of the new files and will also preserve all permissions from the "original / working" WordPress version. The end result is a directory with upgraded WordPress Files and all of the additional or custom stuff from the original site;
cp -R -T -n -v -a -x /var/www/html/WebSiteDirectory.WorkingVersion/* /var/www/html/WebSiteDirectory Don't forget the ASTERISK on the end of the Source. Flags can be combined, IE -Rnvax, but are shown separately for clarity.
- Make sure the wp-config.php file is in the upgrade directory (there shouldn't be a wp-config.php file in the upgrade folder and it should be copied with the above CP command)
- Also remember a LOT of extensions use the .htaccess file to modify the behavior of WordPress, so make sure that file from the original version of that file into the upgrade directory (its a hidden file, so make sure).