Running PHP in Linux: how to fix "PHP Startup: Unable to load dynamic library" issues?

363 Views Asked by At

I have determined path to php but I'm getting the following php error in Ubuntu 22.04, I think I would need to load the Mysqlnd and mysqli for this issue

root@xxxx:~# php --ini
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_pdo_mysql.dll' (tried: /usr/lib/php/20190902/php_pdo_mysql.dll (/usr/lib/php/20190902/php_pdo_mysql.dll: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/php_pdo_mysql.dll.so (/usr/lib/php/20190902/php_pdo_mysql.dll.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_mysql.so.so (/usr/lib/php/20190902/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_pdo_mysql.so' (tried: /usr/lib/php/20190902/php_pdo_mysql.so (/usr/lib/php/20190902/php_pdo_mysql.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/php_pdo_mysql.so.so (/usr/lib/php/20190902/php_pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
Configuration File (php.ini) Path: /etc/php/7.4/cli
Loaded Configuration File:         /etc/php/7.4/cli/php.ini
Scan for additional .ini files in: /etc/php/7.4/cli/conf.d
Additional .ini files parsed:      /etc/php/7.4/cli/conf.d/10-opcache.ini,
/etc/php/7.4/cli/conf.d/10-pdo.ini,
/etc/php/7.4/cli/conf.d/20-calendar.ini,
/etc/php/7.4/cli/conf.d/20-ctype.ini,
/etc/php/7.4/cli/conf.d/20-exif.ini,
/etc/php/7.4/cli/conf.d/20-ffi.ini,
/etc/php/7.4/cli/conf.d/20-fileinfo.ini,
/etc/php/7.4/cli/conf.d/20-ftp.ini,
/etc/php/7.4/cli/conf.d/20-gettext.ini,
/etc/php/7.4/cli/conf.d/20-iconv.ini,
/etc/php/7.4/cli/conf.d/20-json.ini,
/etc/php/7.4/cli/conf.d/20-phar.ini,
/etc/php/7.4/cli/conf.d/20-posix.ini,
/etc/php/7.4/cli/conf.d/20-readline.ini,
/etc/php/7.4/cli/conf.d/20-shmop.ini,
/etc/php/7.4/cli/conf.d/20-sockets.ini,
/etc/php/7.4/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.4/cli/conf.d/20-sysvsem.ini,
/etc/php/7.4/cli/conf.d/20-sysvshm.ini,
/etc/php/7.4/cli/conf.d/20-tokenizer.ini

enter image description here

I don't know what the exact steps is needed to follow. Kindly advise to load the Mysqlnd and mysqli

2

There are 2 best solutions below

2
Cse Rajesh On BEST ANSWER

I've commented the following extenstion in this path /etc/php/7.4/cli/php.ini and issue got resolved.

;extension=php_pdo_mysql.dll
;extension=pdo.so
;extension=pdo_mysql.so
;extension=php_pdo_mysql.so
3
JureW On

I think you edited php ini the wrong way, or downloaded wrong PHP version as dll files are from windows, linux uses so So smth like:

extension=/path/to/extension/mysqli.so

is what you are searching for. Download proper extensions (if missing), put them into the folder, add path in php.ini. More details (from my php.ini):

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;
;   extension=modulename
;
; For example:
;
;   extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
;   extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.

Also, to get the proper location for php.ini, use php --ini