“500 Internal Server Error” after switching a WordPress site to PHP 7.3

This post was most recently updated on February 21st, 2019.

Reading Time: 4 minutes.

Now for something totally different – for a change, I got to fix an issue with my own blog, so I had the chance to delve into PHP and WordPress configurations… :)

PHP is an ever-evolving language – even if it might not always feel that way. The old workhorse has been powering most of the internet for a couple of decades, and weirdly enough, doesn’t really show signs of going anywhere.

A huge part of the success story has been the fact that WordPress, the most popular website platform in the world, is built on it.

PHP 5 was released in 2004(!), and 5.6 was the last version of PHP 5 that was still recently supported. It reached its end-of-life at the beginning of 2019, so it was a good time to upgrade.

Update 21.2.2019: With WordPress 5.1 (just published), the platform now complains if you’re using old versions of PHP! That’s a great move if you ask me – even though WordPress works just fine with older versions, it’s safer and faster to run later and up-to-date versions. Currently, it’ll complain about anything below 5.6, but hopefully that version will be bumped up as soon as possible. See below for the warning in action:

WordPress 5.1 now bugs you to update your PHP version if you're running and old and insecure version.
WordPress 5.1 now bugs you to update your PHP version if you’re running and old and insecure version. (read more)

Upgrading from PHP 5.6

Looking at the options today, 7.0 is already deprecated, so I’m left with 7.1, 7.2 and 7.3, the last 2 of which are still completely supported. 7.1 only receives security fixes currently.

Each new version brings new improvements and features, but also could deprecate old features or even remove modules or functions that your current solutions rely on… So before choosing the correct version, it’s wise to check any compatibility information your current solution providers offer.

My primary interest in this particular case was WordPress, as that’s the platform my current blog is hosted on. WordPress has compatibly info available here: https://wordpress.org/about/requirements/

From PHP 5.6 straight to PHP 7.3

Well, that’s simple and straightforward. At the time of writing, PHP 7.3 is the recommendation for WordPress, but versions all the way back to early 2000s are supported.

Since WordPress didn’t seem to have any issues, I started looking at my plugins – but most of them don’t have much info available in regards of PHP compatibility, so soon enough I gave up. Post-upgrade, I’d always have the option to downgrade.

So I went forward with the upgrade, jumping directly to PHP 7.3. When hitting refresh a few times afterwards, I was faced with this error:

PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect()

Ouch. Sounds like something very elementary is now broken. If WordPress can’t access the database hosting its data, there isn’t much it’s going to do.

So, I started digging. This is what I found in the error_log:

[07-Jan-2019 20:36:35 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in [site]public_html/[site]/wp-includes/wp-db.php:1564
Stack trace:
#0 [site]public_html/[site]/wp-includes/wp-db.php(592): wpdb->db_connect()
#1 [site]public_html/[site]/wp-includes/load.php(409): wpdb->__construct('...', '...', '...', '...')
#2 [site]public_html/[site]/wp-settings.php(106): require_wp_db()
#3 [site]public_html/[site]/wp-config.php(91): require_once('[site]...')
#4 [site]public_html/[site]/wp-load.php(37): require_once('[site]...')
#5 [site]public_html/[site]/wp-blog-header.php(13): require_once('[site]...')
#6 [site]public_html/[site]/index.php(17): require('[site]...')
#7 {main}
  thrown in [site]public_html/[site]/wp-includes/wp-db.php on line 1564

So mysql_connect() is broken. Why?

Well, that might be because that function was already deprecated in PHP 5.5 and removed in PHP 7.0.

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide.

http://php.net/manual/en/function.mysql-connect.php

I tested PHP 7.2 as well, and to my surprise our worked. I didn’t think it should, though… The PHP team already removed the command in version 7.0! But comparing the default configuration for the PHP extensions revealed the issue:

For PHP 7.2, the default extensions are different. My guess is that for whatever reasons, 7.3 didn’t have the module overwriting the deprecated and removed function available by default whereas 7.2 did.

How to get WordPress to work with PHP 7?

If you still want to continue using your WordPress installation (I mean, you could take this as a sign, right?) you should be able to do that. After comparison, I narrowed the missing extension down to nd_mysqli.

Just navigate to your web hosting panel and enable the module called nd_mysqli. There’s a fair chance your extension name could be different, though – web hosting providers are different.

Enabling the extension nd_mysqli to get mysql_connect() to work.
Enabling the extension nd_mysqli to get mysql_connect() to work.

After this, your site should load just fine again! Fixed the issue for me at the very least.

And if you’re in luck, you’ll see performance gains from the upgrade – at the very least, you’ll be more secure in the future.

The exact configuration of different extensions is of course different for different hosting providers. You might not need to take these steps at all, or the extension might be named differently. But I thought documenting them is useful anyway! :)

Antti K. Koskela

Antti Koskela is a proud digital native nomadic millenial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world.

He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.

This is his personal professional (e.g. professional, but definitely personal) blog.

6
Leave a Reply

avatar
5000
3 Comment threads
3 Thread replies
2 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
JuliaAntti K. KoskelaDanielJoe Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Joe
Guest
Joe

Thanks! It worked, and if I hadn’t updated now they’d have been on PHP 8 by the time I thought of it again!

Daniel
Guest
Daniel

Thanks you very much for this! Much appreciated!
Got a 500 error thrown when switching to PHP 7.3 and didn’t honestly know what to do. This fixed the it :)
Thanks again!

Julia
Guest

I very rarely comment on posts, but you, Antti are a genius. I am upgraded my client sites and got the darn error, instead of spending hours trying to sort it out, I found your blog post. You are a legend and an absolute lifesaver.

Thanks again!