MySQLi not found dockerized php

丶灬走出姿态 提交于 2020-07-15 04:34:20

问题


I'm trying to dockerize my website. I've got Nginx and PHP up and running and it's working find except I can't connect to a db. When the page is loaded I get the error:

Fatal error: Uncaught Error: Class 'MySQLi' not found in /private/conn.php:8 Stack trace: #0 /public_html/index.php(2): require() #1 {main} thrown in /private/conn.php on line 8

My connection line on line 8 is:

$db = new mysqli("$host", "$user", "$pass", "$db", "$port");

Now this used to work fine on my old set up but since moving to a new one and installing php7.1.5 I can't get it running. Now, I haven't used the mysqlnd so this may be a misunderstanding on my part but the mysqlnd includes the mysqli driver.

Output of phpinfo:

How can I get this running? Or should I be using a different driver now?


回答1:


You need to enable the php extension in your Dockerfile:

FROM php:7
RUN docker-php-ext-install mysqli

There is no need to touch php.ini.




回答2:


i had similar issue with
php:7-apache image, which by default will not have mysqli installed
you can verify this inside the container

$ docker exec -it <phpcontainerid> bash  

inside the docker container bash terminal

# docker-php-ext-enable mysqli

if mysqli is not installed which you will come to know from the output of above command

# docker-php-ext-install mysqli

then i commited this change so the same image

$ docker commit -p <phpcontainerid> <new or same image name>



回答3:


It looks like you don't have the MysqlI extension enabled in your php.ini. If enabled, you should see a section mysqli in your phpinfo.

More info on enabling the extension can be found here: Fatal error: Class 'MySQLi' not found




回答4:


works for me:

inside php container:

docker-php-ext-install mysqli

apachectl restart
  • docker images: mysql, php:7.2.30-apache

https://github.com/docker-library/php/issues/391



来源:https://stackoverflow.com/questions/46879196/mysqli-not-found-dockerized-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!