Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Startup: Unable to load dynamic library 'mysqli' undefined symbol: mysqlnd_global_stats

Tags:

php

cron

mysqli

My entire site runs flawlessly via browser. I have just added a cron job, and each time it runs this error gets triggered:

PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20180731/mysqli (/usr/lib/php/20180731/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/mysqli.so (/usr/lib/php/20180731/mysqli.so: undefined symbol: mysqlnd_global_stats))

Not sure what is going on. I have logged PHP version both using the browser, and using cron, and it came out the same: 7.3.2-3+0~20190208150725.31+stretch~1.gbp0912bd

What is so different in cron? How can i fix this?

like image 667
Boriss Avatar asked Jun 08 '19 16:06

Boriss


3 Answers

Try altering your php.ini file in both php/[version]/apache2 to resemble this:

extension=mysqlnd
extension=mysqli

Loading mysqlnd first eliminates the error on my debian VM. If you intend to run the same code at the command line, you may wish to consider altering php/[version]/cli/php.ini as well.

like image 117
Michael McPherson Avatar answered Oct 07 '22 23:10

Michael McPherson


I have 2 solutions.

Solution one: I noticed that closing the mysql connection at the end of the script solves the problem.

Solution two: As it turns out, there was a difference between /etc/php/7.3/cli/php.ini and /etc/php/7.3/fpm/php.ini.

The first one has this line:

    extension=mysqli

The second one hat this (note the semicolon):

;    extension=mysqli

Adding the semicolon to /etc/php/7.3/cli/php.ini completly fixed my issue.

like image 44
Boriss Avatar answered Oct 08 '22 00:10

Boriss


comment it out from /etc/php/[version]/cli/php.ini:

;extension=mysqli

leave it as is in /etc/php/[version]/apache2/php.ini:

extension=mysqli

reload apache2:

sudo systemctl restart apache2
like image 1
alboforlizo Avatar answered Oct 07 '22 22:10

alboforlizo