0

I'm trying to connect my Wordpress 6.1.1 installation installed on an Azure VM (Ubuntu) to my DB, also installed on Azure. I ran the "php -m" command to get the list of available PHP extensions on the server and I got this list:

Core ctype curl date dom fileinfo filter ftp hash iconv json libxml mbstring mysqlnd openssl pcre PDO pdo_sqlite Phar posix readline Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib

I'm trying to use PDO (which is listed and therefore available) to connect with the following code in wp-config.php

define( 'DB_NAME', 'nome_database' );
define( 'DB_USER', 'nome_utente' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'host' );
define( 'DB_CHARSET', 'utf8' );

$pdo = new PDO( "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD, 
array( PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING ) );

but I get the following error:

Fatal error: Uncaught PDOException: could not find driver in /home/site/wwwroot/wp- 
config.php:57 Stack trace: #0 /home/site/wwwroot/wp-config.php(57): PDO- 
>__construct('mysql:host=MYHOST...', 'USERNAME...', '***********', Array) #1 
/home/site/wwwroot/wp-load.php(50): require_once('/home/site/wwwr...') #2 
/home/site/wwwroot/wp-blog-header.php(13): require_once('/home/site/wwwr...') #3 
/home/site/wwwroot/index.php(17): require('/home/site/wwwr...') #4 {main} thrown in 
/home/site/wwwroot/wp-config.php on line 57

Can you help me understand what's going on? Thanks a lot!

Claudio M
  • 65
  • 6
  • Please write the whole question in English, not just parts of it. – M. Eriksson Jan 26 '23 at 15:35
  • I also tried with a Mysqli string: $con=mysqli_init(); mysqli_ssl_set($con, NULL, NULL, "/home/site/wwwroot/ssl/DigiCertGlobalRootCA.crt.pem", NULL, NULL); mysqli_real_connect($con, "mysql.mysql.database.azure.com", "myuser@mysql", "mypassword", "mydbname", 3306); but i receive this: Fatal error: Uncaught Error: Call to undefined function mysqli_init() in /home/site/wwwroot/wp-config.php:57 Stack trace: #0 /home/site/wwwroot/wp-load.php(50): require_once() #1 /home/site/wwwroot/wp-blog-header.php(13): require_once('/home/site/wwwr...') – Claudio M Jan 26 '23 at 15:45

1 Answers1

0
/home/site/wwwroot/wp-  config.php:57 Stack trace: #0
/home/site/wwwroot/wp-config.php(57): PDO- ```

This error code occurs when the PHP-MYSQL extension is not properly installed in your local VM, Even when PDO extension-

mysqlnd openssl pcre PDO pdo_sqlite

is installed in your VM you need to additionally install the PHP-MYSQL driver in the VM for the PDO extension to function properly

You can try installing the php-mysql package with the below commands:-

sudo apt-get update

enter image description here

sudo apt-get install php-mysql

enter image description here

Alternatively, you can run these commands to install all 3 packages together:-

sudo apt install php libapache2-mod-php php-mysql -y

OR


sudo apt update
sudo apt install apache2 \
                 ghostscript \
                 libapache2-mod-php \
                 mysql-server \
                 php \
                 php-bcmath \
                 php-curl \
                 php-imagick \
                 php-intl \
                 php-json \
                 php-mbstring \
                 php-mysql \
                 php-xml \
                 php-zip

enter image description here

php -m

enter image description here

Restart your WordPress server and try the DB connection again.

sudo service apache2 restart

enter image description here

You can also explicitly navigate to the php-extension file and validate its status too. Make sure to check the status of the server on which your WordPress is running and restart that server.

Extension commands:-

extension=pdo.so
extension=pdo_mysql.so

References:-

Install and configure WordPress | Ubuntu

php - Installing PDO driver on MySQL Linux server - Stack Overflow By Jani Hartikainen artagis, Avinash Tiwari,

PHP: MySQL (PDO) - Manual

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11