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

0

On a server with Debian 9, I upgraded PHP from version 7.2.13 to version 7.3.0, but now the PDO does not work anymore.

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

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 file /etc/php/7.3/apache2/php.ini is with pdo_mysql enabled.

;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 /etc/php/7.3/apache2/php.ini file is the php.ini 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:

  • Without any files .htaccess .
  • Without any files .user.ini .
  • Apache2 has already been restarted.
  • I'm using the same code that worked well with PHP version 7.2.13.

Thank you!

    
asked by anonymous 13.12.2018 / 23:51

1 answer

0

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, perhaps the extension does not is available, which may only emit error in display_startup_errors .

To take the real test (did not test) 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 display_startup_errors=1 flag should issue an error if the pdo_mysql extension, an error type that is only issued when Apache starts or when it executes PHP through the terminal.

If the problem is that the extension has actually been installed on your machine / workstation then confirm that after installing php7.3 you have executed the following commands (you must do in su or sudo ):

 apt-get install php7.3-mysql

After installing mysql enable the module:

 phpenmod pdo_mysql

After restarting Apache:

 service apache2 restart
    
14.12.2018 / 16:12