How to upgrade wordpress: Difference between revisions

From Mass Pirate Wiki
Jump to navigationJump to search
(initial revision)
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
How to Upgrade Wordpress
Wordpress (in my humble opinion) is not the most
Wordpress (in my humble opinion) is not the most
administrator-friendly piece of software to upgrade.  Generally, one
administrator-friendly piece of software to upgrade.  Generally, one
Line 19: Line 17:


   mysqldump -u USER -pPASSWD masspira_wrd1 --complete-insert --verbose \
   mysqldump -u USER -pPASSWD masspira_wrd1 --complete-insert --verbose \
     | gzip -9 > masspira_wrd1.YYYYMMDD.sql.gz
     | gzip -9 > masspira_wrd1.$(date +%F).sql.gz


Of course, you'll need to replace "USER" with a mysql username, PASSWD
Of course, you'll need to replace "USER" with a mysql username, and PASSWD
with USER's password, and YYYYMMDD with the current year, month, and
with USER's password.
date.


To backup the site files:
To backup the site files:

Latest revision as of 09:33, 9 May 2015

Wordpress (in my humble opinion) is not the most administrator-friendly piece of software to upgrade. Generally, one test-drives upgrades in a development environment: you copy the site files to a local development environment, test drive the upgrade there; if all goes well, you use a source control system to propagate the code changes to the `live' site.

Wordpress insists on using fully qualified URLs for, well, just about everything, and this makes the "upgrade and promote" strategy a royal pain in the arse. Instead, I've been opting for a "backup and upgrade" strategy.

There are two things to backup: wordpress's database, and the site code.

To backup the database:

 mysqldump -u USER -pPASSWD masspira_wrd1 --complete-insert --verbose \
    | gzip -9 > masspira_wrd1.$(date +%F).sql.gz

Of course, you'll need to replace "USER" with a mysql username, and PASSWD with USER's password.

To backup the site files:

 $ git status
 # On branch master
 nothing to commit (working directory clean)

cd to the blog's document root. Verify that "git status" says "working directory clean". If git mentions anything about uncommitted changes, add and commit the files in question, to get a clean working directory.

Once you have a clean working directory, tag it

 $ git tag savepoint-YYYYMMDD

At this point, you're safe to do the upgrade. If the upgrade goes badly, you can revert to the old version by:

  • Restoring the database backup you created with mysqldump, and
  • git checkout savepoint-YYYYMMDD

In terms of upgrading, I generally use wordpress's UI. That seems to be the path the wordpress encourages people to use, and I'm hoping its the most reliable.

After upgrading, you'll need to cd to the site's document root, and commit changes to source control. Here's the basic process:

 0 rose:~/masspirates.org/web/blog$ git status
 # On branch master
 # Changes not staged for commit:
 #   (use "git add/rm <file>..." to update what will be committed)
 #   (use "git checkout -- <file>..." to discard changes in working directory)
 #
 #       modified:   license.txt
 #       modified:   readme.html
 #       modified:   wp-admin/about.php
 #       modified:   wp-admin/async-upload.php
 #       modified:   wp-admin/includes/ajax-actions.php
 #       modified:   wp-admin/includes/taxonomy.php
 #       modified:   wp-admin/includes/update-core.php
 #       modified:   wp-admin/js/common.js
 #       modified:   wp-admin/js/common.min.js
 #       modified:   wp-admin/js/customize-controls.js
 #       modified:   wp-admin/js/customize-controls.min.js
 #       modified:   wp-admin/update-core.php
 #       modified:   wp-admin/user-edit.php
 #       modified:   wp-includes/class-wp-customize-control.php
 #       modified:   wp-includes/class-wp-customize-manager.php
 #       modified:   wp-includes/class-wp-customize-setting.php
 #       modified:   wp-includes/date.php
 #       modified:   wp-includes/general-template.php
 #       modified:   wp-includes/js/media-audiovideo.js
 #       modified:   wp-includes/js/media-audiovideo.min.js
 #       modified:   wp-includes/js/media-grid.js
 #       modified:   wp-includes/js/media-grid.min.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.min.js
 #       deleted:    wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png
 #       modified:   wp-includes/js/tinymce/wp-tinymce.js.gz
 #       modified:   wp-includes/link-template.php
 #       modified:   wp-includes/script-loader.php
 #       modified:   wp-includes/taxonomy.php
 #       modified:   wp-includes/update.php
 #       modified:   wp-includes/version.php
 #
 no changes added to commit (use "git add" and/or "git commit -a")

The general gist is to do "git add" on added or modified files, and "git rm" on removed files. Like so:

 $ git add license.txt readme.html wp-admin wp-includes
 0 masspiratesweb@rose:~/masspirates.org/web/blog$ git status
 # On branch master
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #       modified:   license.txt
 #       modified:   readme.html
 #       modified:   wp-admin/about.php
 #       modified:   wp-admin/async-upload.php
 #       modified:   wp-admin/includes/ajax-actions.php
 #       modified:   wp-admin/includes/taxonomy.php
 #       modified:   wp-admin/includes/update-core.php
 #       modified:   wp-admin/js/common.js
 #       modified:   wp-admin/js/common.min.js
 #       modified:   wp-admin/js/customize-controls.js
 #       modified:   wp-admin/js/customize-controls.min.js
 #       modified:   wp-admin/update-core.php
 #       modified:   wp-admin/user-edit.php
 #       modified:   wp-includes/class-wp-customize-control.php
 #       modified:   wp-includes/class-wp-customize-manager.php
 #       modified:   wp-includes/class-wp-customize-setting.php
 #       modified:   wp-includes/date.php
 #       modified:   wp-includes/general-template.php
 #       modified:   wp-includes/js/media-audiovideo.js
 #       modified:   wp-includes/js/media-audiovideo.min.js
 #       modified:   wp-includes/js/media-grid.js
 #       modified:   wp-includes/js/media-grid.min.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.min.js
 #       modified:   wp-includes/js/tinymce/wp-tinymce.js.gz
 #       modified:   wp-includes/link-template.php
 #       modified:   wp-includes/script-loader.php
 #       modified:   wp-includes/taxonomy.php
 #       modified:   wp-includes/update.php
 #       modified:   wp-includes/version.php
 #
 # Changes not staged for commit:
 #   (use "git add/rm <file>..." to update what will be committed)
 #   (use "git checkout -- <file>..." to discard changes in working directory)
 #
 #       deleted:    wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png

git rm the deleted file, and check

 $ git rm wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png
 rm 'wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png'
 0 rose:~/masspirates.org/web/blog$ git status
 # On branch master
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #       modified:   license.txt
 #       modified:   readme.html
 #       modified:   wp-admin/about.php
 #       modified:   wp-admin/async-upload.php
 #       modified:   wp-admin/includes/ajax-actions.php
 #       modified:   wp-admin/includes/taxonomy.php
 #       modified:   wp-admin/includes/update-core.php
 #       modified:   wp-admin/js/common.js
 #       modified:   wp-admin/js/common.min.js
 #       modified:   wp-admin/js/customize-controls.js
 #       modified:   wp-admin/js/customize-controls.min.js
 #       modified:   wp-admin/update-core.php
 #       modified:   wp-admin/user-edit.php
 #       modified:   wp-includes/class-wp-customize-control.php
 #       modified:   wp-includes/class-wp-customize-manager.php
 #       modified:   wp-includes/class-wp-customize-setting.php
 #       modified:   wp-includes/date.php
 #       modified:   wp-includes/general-template.php
 #       modified:   wp-includes/js/media-audiovideo.js
 #       modified:   wp-includes/js/media-audiovideo.min.js
 #       modified:   wp-includes/js/media-grid.js
 #       modified:   wp-includes/js/media-grid.min.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
 #       modified:   wp-includes/js/tinymce/plugins/wpeditimage/plugin.min.js
 #       deleted:    wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png
 #       modified:   wp-includes/js/tinymce/wp-tinymce.js.gz
 #       modified:   wp-includes/link-template.php
 #       modified:   wp-includes/script-loader.php
 #       modified:   wp-includes/taxonomy.php
 #       modified:   wp-includes/update.php
 #       modified:   wp-includes/version.php


Now commit the changes, and push them to our central repository:

 0 rose:~/masspirates.org/web/blog$ git commit -m "upgraded to wordpress 4.1.1"
 [master 098bac2] upgraded to wordpress 4.1.1
  31 files changed, 232 insertions(+), 102 deletions(-)
  rewrite wp-admin/js/common.min.js (77%)
  rewrite wp-admin/js/customize-controls.min.js (95%)
  rewrite wp-includes/js/media-audiovideo.min.js (95%)
  rewrite wp-includes/js/media-grid.min.js (62%)
  delete mode 100644 wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png
 0 rose:~/masspirates.org/web/blog$ git push origin
 Counting objects: 82, done.
 Delta compression using up to 4 threads.
 Compressing objects: 100% (43/43), done.
 Writing objects: 100% (43/43), 69.95 KiB, done.
 Total 43 (delta 36), reused 0 (delta 0)
 Unpacking objects: 100% (43/43), done.
 To file:///home/members/masspirateparty/sites/masspirates.org/users/masspiratesweb/masspirates.org/include/git/blog
    e311704..098bac2  master -> master

At the very end, you should be able to do this:

 $ git status
 # On branch master
 nothing to commit (working directory clean

As before, the goal is to end up with "working directory clean".

What if you only need to upgrade plugins? Same process: get a clean working directory, backup the database, tag, upgrade, add changed files, commit and pushed.

For theme upgrades, it's generally worth going through the trouble of doing a dev environment test drive. Sometimes theme changes can make a the site look a lot different; you may have to do some tweaking before going live with the new theme.