MajklRS
MajklRS

Reputation: 101

MySQLi not found in docker php container

Error:

Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/index.php:16 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 16

I made the index.php file and PDO mysql connection example code. Everything working as expected, except MySQLi connection. I added docker-php-ext-install run command to docker file but that did not help.

Here is my PHP docker file:

FROM php:7.0-fpm
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN docker-php-ext-enable mysqli 

My docker-compose.yml file:

nginx:  
 build: ./nginx/
 container_name: nginx-container
 ports:
  - 8080:80
 links:
  - php
 volumes_from:
  - app-data

php:  
 build: ./php/
 container_name: php-container
 expose:
  - 9000
 links:
  - mysql
 volumes_from:
  - app-data

app-data:  
 #image: php:7.0-fpm
 build: ./php/
 container_name: app-data-container
 volumes:
  - ./www/html/:/var/www/html/
  - ./nginx/nginx:/etc/nginx/conf.d
 command: “true”

mysql:  
 #image: mysql:5.7
 build: ./mysql/
 container_name: mysql-container
 expose:
  - 3306
 ports:
  - 3306:3306
 volumes_from:
  - mysql-data
 environment:
  MYSQL_ROOT_PASSWORD: secret
  MYSQL_DATABASE: zavrel_db
  MYSQL_USER: user
  MYSQL_PASSWORD: password

mysql-data:  
 image: mysql:latest
 container_name: mysql-data-container
 volumes:
  - /var/lib/mysql
 command: "true"

phpmyadmin:  
 image: phpmyadmin/phpmyadmin
 container_name: phpmyadmin-container
 ports:
  - 8888:80
 links:
  - mysql
 environment:
  PMA_HOST: mysql

Thank you.

Upvotes: 2

Views: 4449

Answers (3)

ywoume
ywoume

Reputation: 21

I found the problem, the package is RUN pdo_mysqliso i've added this RUN docker-php-ext-install pdo_mysqli in my docker-compose

Upvotes: 0

MajklRS
MajklRS

Reputation: 101

I solved the problem by deleting all images and containers. After that, I started and everything is fine.

docker rmi $(docker images -a -q)
docker rm $(docker ps -a -q)

Upvotes: 3

Meiram Chuzhenbayev
Meiram Chuzhenbayev

Reputation: 906

Try change name of packet

php-mysqli

Upvotes: 3

Related Questions