Homebrew PHP 7.4 upgrade fails on MacOS 10.15.1 Catalina

My attempts to upgrade homebrew PHP 7.3.12 to PHP 7.4.0 have failed.

Here’s what I did:

brew update
sudo brew services stop php
brew upgrade
brew cleanup
brew doctor
sudo brew services start php
brew services list
sudo reboot now

Here’s what I expected:

The server to come back up as expected.

Here’s what happened:

WordPress 5.3 frontend and backend both report the dreaded “Error establishing a database connection” error.

phpMyAdmin reports the following three errors:

  1. Cannot log in to the MySQL server
  2. mysqli_real_connect(): Unexpected server response while doing caching_sha2 auth: 109
  3. mysqli_real_connect(): (HY000/2006): MySQL server has gone away

Here’s what I did next:

Ensured correct username and password for MySQL.
Ensured correct hostname.
Ensured MySQL is running:

mysqladmin -u root -p status
Enter password:
Uptime: 173  Threads: 2  Questions: 3  Slow queries: 0  Opens: 113  Flush tables: 3  Open tables: 35  Queries per second avg: 0.017

Made the following changes to the PHP 7.4 ext-opcache.ini file:

opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 50000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 2

Made the following changes to the PHP 7.4 php.ini file:

expose_php = Off
max_execution_time = 90
max_input_time = 90
max_input_vars = 2000
memory_limit = -1
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
upload_max_filesize = 3G
post_max_size = 0
default_socket_timeout = 180
date.timezone = America/Chicago
pdo_mysql.default_socket = /tmp
mysqli.default_socket = /tmp/mysql.sock

installed the following PHP 7.4 extensions:

pecl channel-update pecl.php.net
pecl install apcu
pecl install imagick
pecl install redis

Additional information:

My httpd log reports nothing unusual:

[Sat Nov 30 20:53:48.021678 2019] [mpm_prefork:notice] [pid 140] AH00163: Apache/2.4.41 (Unix) OpenSSL/1.1.1d configured -- resuming normal operations
[Sat Nov 30 20:53:48.021785 2019] [core:notice] [pid 140] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'

Similarly, my MySQL log reports nothing unusual:

2019-12-01T03:07:00.6NZ mysqld_safe Logging to '/usr/local/var/mysql/moriarty.local.err'.
2019-12-01T03:07:00.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2019-12-01T03:07:02.994684Z 0 [System] [MY-010116] [Server] /usr/local/opt/mysql/bin/mysqld (mysqld 8.0.18) starting as process 398
2019-12-01T03:07:03.012177Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-12-01T03:07:06.203718Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-12-01T03:07:06.277615Z 0 [System] [MY-010931] [Server] /usr/local/opt/mysql/bin/mysqld: ready for connections. Version: '8.0.18'  socket: '/tmp/mysql.sock'  port: 3306  Homebrew.
2019-12-01T03:07:06.337877Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '' port: 33060

Are there no errors logged by PHP?

No sir – not a single error.

Did you try restarting httpd? (Personally I use nginx and a remote database so I’m a bit out of my depth here)

Yes, restarted httpd and rebooted several times.

and php -v and php -i all relay the expected information?

What version of mysql/did it also get upgraded?

MySQL is at 8.0.18_1 and was not upgraded.

This seems to be a PHP/MySQL thing where they’ve changed the default authentication plugin.

If you’re not able to log into your mysql database with mysql -uroot the simple fix is to create the directory mysql is looking for: mkdir /usr/local/etc/my.cnf.d

This is because brew cleanup deletes the (empty) my.cnf.d directory.
It’s only a temporary fix, a more permanent one would be to edit /usr/local/etc/my.cnf and comment out the line that includes the mentioned directory.

Hope it helps! :slight_smile:

php -v and php -i both report expected information, but I’ve since rolled back to php@7.3 (PHP 7.3.12).

There’s no such directory reference or directive in my /usr/local/etc/my.cnf file. Never has been to my knowledge.

I’ve since rolled back to php@7.3 (PHP 7.3.12).

Saw this response on another post:

This is a bug. I will take a wild guess that it has to do with bumping up the version of mysqlnd client API library version to 7.4.0 from the previous 5.0.12.

While you could temporarily set the default authentication plug-in to native password by adding default_authentication_plugin = mysql_native_password to the [mysqld] section of my.cnf which is QUITE LESS SECURE , I would recommend downgrading php (I can confirm version 7.3.1 runs successfully and probably other 7.3 versions, too) until it is fixed, unless you’re using the native password mechanism, anyway.

I has to downgrade temporarily by installing “brew install php@7.3” and updating the /usr/local/etc/httpd/httpd.conf file to point to php@7.3

Just a quick note to report that PHP 7.4.1 also fails, with phpMyAdmin reporting the same three errors:

  1. Cannot log in to the MySQL server
  2. mysqli_real_connect(): Unexpected server response while doing caching_sha2 auth: 109
  3. mysqli_real_connect(): (HY000/2006): MySQL server has gone away