In November last year PHP 8 landed. It announced some improvements in performance, speed and security.
Like any good tinkerer, I rushed to upgrade to PHP 8 from 7.4, specifically 7.4.16, the version now running on the server.
Plof! a nice 500 error greets me and breaks the whole site.
500 error in WordPress when upgrading to PHP 8
No URL resolves. I did the typical test to disable all plugins and use default template.
Error 500 would not go away. I was shocked, but I passed the matter convinced that it was still too early to update and, as they advised, the best thing to do was to wait for all plugin and template authors to update their code to make it compatible with PHP 8.
Almost seven months later I tried again and the 500 error was still there. The first clue that the origin of the error is only in this blog is that in the other two WordPress installations that I have in the same server everything works correctly.
As a 500 error can appear for a lot of reasons. The next logical step is to pull the error logs to try to find out what is wrong. I get a string of warnings like this:
PHP Warning: Use of undefined constant minor – assumed ‘minor’ (this will throw an Error in a future version of PHP) in /home/xxxxxx/public_html/blog/wp-config.php on line 11
That is, the constant is supposed to have quotes around it. I go to wp-config.php and indeed, minor appears without quotes on that line.
define (‘WP_AUTO_UPDATE_CORE’, minor);
Searching the WordPress forum I find that many people have had this same problem upgrading to older versions of PHP due to conflicts with a plugin or template.
It cannot be ruled out that that the problem is related to the installation of WordPress that has something broken, as I was told in a ticket that I sent to LucusHost.
In some of the answers they receive, they say that to solve the problem just add the inverted commas to ‘minor’, so try it and that’s what I’m doing.
define (‘WP_AUTO_UPDATE_CORE’, ‘minor’);
WP_AUTO_UPDATE_CORE allows you to control WordPress core updates for minor, major and development versions. This constant can be defined in several ways. Removing this line is not a good idea.
#Disables all core updates:
define( ‘WP_AUTO_UPDATE_CORE’, false );
# Enable all updates, including minor and major updates:
define( ‘WP_AUTO_UPDATE_CORE’, true );
# Enables minor updates:
define( ‘WP_AUTO_UPDATE_CORE’, ‘minor’ );
Good news and bad news
The good news is that now, running PHP 8, the 500 error is gone. Everything seems to work fine at first sight, both plugins and posts. The bad news is that the index is broken and looks like this.
I decided to attack first the post template made with Elementor Pro in case the builder had left some hidden junk, but after going over it and redoing it completely I have ruled out that the error came from there.
Now I’m still expurgating the template (GeneratePress Premium) in a test environment and at least I know where it breaks, but mostly I’m looking in WordPress, which is where I think the crux of the matter is, some stale code dragged in, some filter clogged with grease or whatever :P.
I’m leaving this note here in case someone has had a similar problem and it’s helpful, or if what I’ve written here is helpful, or if you know a thing or two about WP and can provide some more clues to solve it. As soon as I find the definitive fix and the possible explanation, I will update this post.
Related. WordPress and PHP8.0. List of changes, developments and other issues
Read the complete upgrade document