"PDO" class not found after upgrading from PHP 7.2.13 to PHP 7.3.0 in Debian 9

Asked

Viewed 1,439 times

0

On a Debian 9 server, I upgraded PHP from version 7.2.13 to version 7.3.0, but now PDO no longer works.

Fatal error: Uncaught Error: Class 'PDO' not found.

The libs are already installed:

root@/# apt install php7.3-pdo
Reading packages list... Ready
Building dependences tree
Reading state informations... Ready
Note, selecting  'php7.3-common' instead of 'php7.3-pdo'
php7.3-common is already the newest version (7.3.0-1+0~20181206202713.23+stretch~1.gbp076afd).
0 packages updated, 0 new packages instaled, 0 packages to be removed e 0 packages  not updated.
root@/# apt install php7.3-mysql
Reading packages list... Ready
Building dependences tree
Reading state informations... Ready
php7.3-mysql is already the newest version (7.3.0-1+0~20181206202713.23+stretch~1.gbp076afd).
0 packages updated, 0 new packages instaled, 0 packages to be removed e 0 packages  not updated.
root@/#

The archive /etc/php/7.3/apache2/php.ini is with pdo_mysql qualified.

;extension=bz2
;extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop

The phpinfo() informs that the aruqivo /etc/php/7.3/apache2/php.ini is the php.ini that is being used by the Apache Web Server:

Configuration File (php.ini) Path   /etc/php/7.2/apache2

The phpinfo() only returns PDO information in the "Module Authors section":

MySQL driver for PDO    George Schlossnagle, Wez Furlong, Ilia Alshanetsky, Johannes Schlueter

More information:

  • With no file .htaccess.
  • With no file .user.ini.
  • Apache2 has already been restarted.
  • I’m using the same code that worked well with PHP version 7.2.13.

Thank you very much!

1 answer

1

It is possible that you have installed PHP7.3 without installing the PDO, since in many distros some extensions are downloaded only via repository, which makes them optional, so even if you enable it in php.ini, it may not be available, which may just send an error on display_startup_errors.

To take the real test (not tested) try the following command:

php -n "<localização do php.ini usado no apache>/php.ini" -d display_startup_errors=1 -r "new PDO('mysql:dbname=foo;host=bar', 'user', 'pass');"

Of course the answer will issue the error in the terminal:

Fatal error: Uncaught Error: Class 'PDO' not found.

But the flag display_startup_errors=1 should issue error if the extension pdo_mysql, a type of error that is only issued when Apache starts or when running PHP from the terminal.

Taken the test if the problem is whether or not the extension has actually been installed on your machine/station then confirm that after installing php7.3 if you have executed the following commands (you need to do it on su or sudo):

 apt-get install php7.3-mysql

After installing mysql enable the module:

 phpenmod pdo_mysql

Then restart the Apache:

 service apache2 restart

Browser other questions tagged

You are not signed in. Login or sign up in order to post.