Skip to content

Failed WordPress update

There has been some issues identified when a WordPress site has been updated and, as a consequence of this, the site becomes unavailable. Below it is explained how to quickly fix it. Note that this is not a common issue, but it may happens everytime a user tries to upgrade its WordPress site to the most recent version.

Option A

Consider opening a ticket under https://cern.service-now.com/service-portal/?id=sc_cat_item&name=request&se=PaaS-Web-App, pointing to this documentation, in case you find some trouble following the procedure.

User gets logs under the Terminal showing the following (or similar), and the WordPress site becomes unreachable:

Warning: require(/opt/app-root/src/wp-includes/class-wp-theme-json.php): failed to open stream: No such file or directory in /opt/app-root/src/wp-settings.php on line 173

Fatal error: require(): Failed opening required '/opt/app-root/src/wp-includes/class-wp-theme-json.php' (include_path='xxx') in /opt/app-root/src/wp-settings.php on line 173

To fix it, the summary steps are as follows:

  • Open a debug pod based on the wordpress one. Don't try it through the console UI since it can lead into a OOMKilled situation.
  • Manually re-install latest version of WordPress
  • Make special attention to the wp-content folder, which contains user's data.

Procedure is as follows (make sure to perform all steps one by one, and in order):

# Place over your project first
# oc project <your-project>

# Show all pods of your WordPress project. It should contain at least 2, suffixing with `-database` and `-wordpress`.
oc get pods

oc debug pod/<pick-the-wordpress-one>

# Ensure placing over the work directory
bash-4.4$ pwd
/opt/app-root/src

# Copy everything except folders content (wp-admin, wp-includes and wp-content) to /tmp/previous for safety reasons.
# Be careful with wp-content, the one that contains user uploads.
bash-4.4$ mkdir /tmp/previous/
bash-4.4$ cp -R * /tmp/previous/
bash-4.4$ ls -al /tmp/previous/

# Download the most recent version of WordPress
bash-4.4$ mkdir /tmp/wp
bash-4.4$ curl https://wordpress.org/latest.tar.gz -o /tmp/wp/latest.tar.gz
bash-4.4$ tar -xvf /tmp/wp/latest.tar.gz --directory /tmp/wp/

# Delete wp-admin and wp-includes folders
bash-4.4$ rm -rf wp-admin/ wp-includes/

# Copy files over from wp-content/plugins and wp-content/themes to the WordPress installation
# Plugins
bash-4.4$ cp -R /tmp/wp/wordpress/wp-content/plugins/* wp-content/plugins/
# Themes
bash-4.4$ cp -R /tmp/wp/wordpress/wp-content/themes/* wp-content/themes/

# Copy rest of files over
# - Do not use recursive option to avoid copy folder contents, specially from wp-content.
bash-4.4$ cp /tmp/wp/wordpress/* .
cp: -r not specified; omitting directory '/tmp/wp/wordpress/wp-admin'
cp: -r not specified; omitting directory '/tmp/wp/wordpress/wp-content'
cp: -r not specified; omitting directory '/tmp/wp/wordpress/wp-includes'

# Copy wp-admin and wp-includes folders
bash-4.4$ cp -r /tmp/wp/wordpress/wp-admin .
bash-4.4$ cp -r /tmp/wp/wordpress/wp-includes .

# At this point in time WordPress site should be working, but it's preferable to kill the original wordpress pod (not the debug one)
# in order the WordPress site to catch up with latest changes

# if not, consider rolling out (restart) both deployments
oc get deploy
# sample output
# NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
# my-first-wordpress-database    0/1     1            0           29d
# my-first-wordpress-wordpress   0/1     1            0           29d
oc rollout restart deploy/my-first-wordpress-database
oc rollout restart deploy/my-first-wordpress-wordpress

# After a few seconds, your WordPress site should be back.

It's also worth checking the wp-config-sample.php file in case any change has been introduced in the latest release, which can be potentially added to the wp-config.php file, although not very common.

ffi: https://wordpress.org/support/article/updating-wordpress/#step-1-replace-wordpress-files

Option B

If your Wordpress site become unaccessible (persistent 503 error) it might be due to a broken Wordpress automatic update. In the OKD4 console, access the POD for the Wordpress instance and check the logs:

  • if there many errors like 'missing include file ... something.php' then it's probably an incomplete upgrade.

To fix it: access the POD Terminal

Under the Administrator environment, go to Workloads and then Pods. Click under the WordPress pod:

image-43.png

Click on the Terminal tab to access the terminal:

image-44.png

Type the following:

cd wp-content/upgrade/___someid____/wordpress
cp -R * /opt/app-root/src

Then, check if the site come back to life. If the site's OK then clean the upgrade files:

cd /opt/app-root/src/wp-content/upgrade
rm -fr ___someid____

When done, check for more updates and instance validity with:

cd /opt/app-root/src
/usr/local/bin/wp core check-update
/usr/local/bin/wp core update