When your WordPress system states there is an new version available to update, you can upgrade WordPress within the admin itself. However, if you have a WordPress site on a production environment, then understandably you might be a bit cautious about upgrading WordPress on a live site without any testing. Should you version control your website, then you can go about upgrading WordPress using Git.
The process is fairly straightforward. Firstly, run the WordPress upgrade on a local or test environment and commit the modified files.
Usually, an update to the WordPress core will modify files within the wp-admin
and wp-includes
directories. The updated files are downloaded from the WordPress website, applied to the website and the database is upgraded.
A typical WordPress .gitignore
file might look like the below.
*.log wp-config.php wp-content/advanced-cache.php wp-content/backup-db/ wp-content/backups/ wp-content/blogs.dir/ wp-content/cache/ wp-content/upgrade/ wp-content/uploads/ wp-content/mu-plugins/ wp-content/wp-cache-config.php wp-content/plugins/hello.php /.htaccess /license.txt /readme.html /sitemap.xml /sitemap.xml.gz
Therefore any file modifications that the WordPress update makes can be committed and pushed without accidentally committing files that should be ignored.
If you are upgrading WordPress using Git, you should make sure that you have a .gitignore
file that ignores standard files like the wp-config.php
database configuration file. In addition, ensure that your commit message contains a reference to the WordPress update in case of any unexpected errors.
$ git add . $ git commit -m "Upgrading WordPress core"
When you push the file changes up to your remote repository and pull them down onto your production server, you may need to upgrade your WordPress database.
If that’s the case, then you will be presented with the following message.
It is at this stage where you should backup your production database. After you have done so, click the Upgrade WordPress Database
button.
As the message mentions, the database upgrade might take up to several minutes. However if your WordPress instance only requires a minor update, then the database upgrade will be pretty instant.
Upgrading WordPress using Git allows you to take a snapshot of your WordPress files before and after the update. Combine this with backing up the database before running the upgrade will ensure that you can take a safe approach when updating your website.