#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog
>

"500 Internal Server Error" after updating a WordPress site to PHP 7.3

koskila
Reading Time 6 min
Word Count 910 words
Comments 56 comments
Rating 5 (1 votes)
View

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.

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)

Anyway - if you're running anything less than PHP 7.2, you should probably update, as all the earlier versions are either unsupported or only getting security patches.

Upgrading from PHP 5.6

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.

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 it 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.

Since the PHP extension configuration varies by host and server, you could encounter the same 500 error after any PHP update (more or less). I'm fairly certain, that at least updates from PHP 5 to PHP 7.1, PHP 7.2 or 7.3 could cause this issue on a lot of different hosting companies.

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! :)

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Joe
2019-01-16 16:14:37)
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!
2019-01-17 03:29:47
Happy to hear that, Joe! With PHP 7.3, you should be good until at least the end of 2021. By that time, PHP 8.0 might be out already! ;) PHP 8.0 is rumored to come out in 2021, but of course nobody knows, and we don't know about the compatibility yet either. But we'll see!
Daniel
2019-01-26 18:46:46)
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!
2019-01-27 20:37:01
Happy it helped! :)
2019-04-14 04:44:29)
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!
2019-04-16 13:41:44
Thanks for the comment, Julia. Appreciate the feedback, and I'm happy to hear it helped! :)
2019-04-22 09:44:51)
Thanks for this. I used cPanel to choose PHP 7.3 and sure enough, it instantly broke my three sites. A quick google found your post here. Very much appreciated that you took the time to a) research the issue and b) post your findings. Thanks again.
2019-04-22 21:01:26
Happy to hear it helped, Neil!
Chintan
2019-05-03 03:27:29)
Thanks for sharing this.
2019-05-07 02:41:08
Happy to help! 😁
2019-05-08 05:27:12)
MANY THANKS! :D Got my headache why my Wordpress suddenly Error 500 after set my PHP version from 5.6 to 7.3 directly. Seems that unchecked nd_mysqli is the default setting. After I checked and click "use current" in my cPanel webhosting, it work normally. :)
2019-05-08 08:06:05
Hi Anugrah, Happy to hear it helped! :)
Tony
2019-05-10 18:38:40)
Great! Fixed my issue, many thanks! :)
2019-05-12 03:26:10
Hi Tony, Happy to be of help! :)
Tony
2019-05-10 18:40:16)
And Ive bookmarked your site! Cheers again :)
Ana
2019-05-17 09:01:33)
OMG! Just lost 2 days trying to figure out why i was getting the http 500 error and it was only necessary to check an option! You really helped me :) Thank you so much!
2019-05-18 06:44:35
Thanks for your comment, Ana! Happy to be of help :)
Jeremy
2019-06-17 22:22:56)
Very helpful! This saved the day for me too. Much appreciated. I went ahead and enabled nd_PDO_mysql in addition to nd_mysqli. Any thoughts as to if that has any ramifications? My site appears to function without nd_PDO_mysql enabled but some other places say to check both boxes so I did.
2019-06-18 15:13:57
Hi Jeremy! Happy it helped! Overall, the fewer modules/extensions/plug-ins you enable in any system, the smaller your (theoretical) attack surface is (the less code there is active, the less bugs there will be). This might be a bit academical in this case - a pragmatic approach would be to keep whatever configuration that works for you, and not worry about it too much (as long as you DO keep your WordPress up-to-date, that is!)
Milan
2019-06-20 21:49:47)
You're fantastic! Thank you for this!
2019-06-21 15:18:19
Happy to be of help, Milan :)
PHP Web Development
2019-07-05 06:54:20)
Nice post! Thanks for sharing.
Brice
2019-07-27 06:06:05)
My website works with 7.2 but not with 7.3. I enable nd_mysqli module and it works with 7.3. Thx a lot !
2019-07-27 16:24:50
Thanks for the comment, Brice, happy it helped! :)
Sonia
2019-08-21 13:53:51)
Thank you very much! this was really helpfull, i had the same message error i was on 5.6 and when i tryed to move to 7.3 made a error but 7.2 seems to works for now!
2019-08-21 14:37:42
Happy to hear it helped! It's a good idea to move to 7.3 though, and just make sure to activate the right plugins :)
Akash Sarkar
2019-08-24 00:43:44)
Thank you very much. It worked!
2019-08-24 07:06:27
Happy to hear that, Akash!
brian
2019-08-29 01:34:19)
Where can I find this option in DirectAdmin? I got the same issue, php 7.3 is not working, but once i go back to php 7.2 wordpress is working again. under my domain in DirectAdmin i'm only able to select the php version. An option for extentions i'm unable to find. Thank you already.
2019-11-14 16:12:01)
I have experienced the same problem in two of my websites, of which PHP version I upgraded to 7.x and I was desperately looking for a solution... Then I found this article and the problem is gone! Thanks a lot Antti :)
2019-11-15 15:14:42
Happy to hear it helped! 😁
2019-11-15 08:13:24)
Thank you! Huge help!
2019-11-15 15:15:10
Happy to be of help, Paul 😄
Ionut Neamtu
2019-11-22 08:46:29)
Thak you very much! You save my time!!! I works!
2019-11-22 09:48:51
Happy to hear it helped, Ionut! :)
Steve
2020-01-02 16:52:54)
Thank you so much for posting this, I got the 500 error after upgrading PHP to 7.3, a quick tick in the mysqli box got the sites back up and running again, you are a life saver.
2020-01-04 23:08:15
Thanks for the comment, Steve! Happy to hear it helped! :)
2020-01-28 15:23:27)
Thank you for the help. In my case i just had to re-check the "mysqli" in the cPaner-> PHP Versions selector which was by default unchecked after setting PHP to vers. 7.3 best regards, Mike
2020-01-28 23:06:20
Thanks for sharing, Mike! The exact configuration (available and required modules) might indeed depend on the server configuration :)
2020-03-17 16:23:38)
Thank you for a brilliant post. My host had no idea what to suggest. I enabled these modules in 7.3 and all my sites came back up!
2020-03-19 21:46:15
Happy to hear it was helpful, Andrzej!
Chris
2020-07-13 21:34:22)
i can't see the option to tick or untick "mysql" on hostgator cpanel and after upgrading to php73 from multiPHP manager i got internal server error.....please help !
Antti K. Koskela
2020-07-14 23:15:52
Hi Chris, Not familiar with multiPHP Manager - does it let you configure different extensions for different PHP versions? Hostgator might also be able to help you out with this one :) Cheers!
2020-11-24 11:18:29)
Hi,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.
Antti K. Koskela
2020-11-24 21:13:18
Thanks for your comment - happy to hear it was helpful! :)
2021-11-01 21:08:24)
Thank you, upgrading From PHP 5.6 straight to PHP 7.3 worked for me.
2021-11-09 17:56:48
My pleasure, happy to hear it was helpful!