bielu000
bielu000

Reputation: 2241

Docker + mysql + php + Symfony, error during connecting to mysql

I'm trying to set up my docker with php app (Symfony 3).

Everything seems to be fine but, Symfony can't connect to mysql.

I have the error:

Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred in driver: could not find driver"

My docker-compose.yaml file is:

version: '3'
    services:
      app:
        image: car-rental
        ports: 
          - "8888:80"
        links:
          - php
          - db 
        volumes:
          - ./.code:/var/www/html
        depends_on:
          - db
      php:
        image: php:7.1-fpm
        volumes:
          - ./.code:/var/www/html  
      db:
        image: mysql:5.7
        volumes:
          - mysql-data:/var/lib/mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: test
          MYSQL_DATABASE: rental

    volumes:
      mysql-data:

Upvotes: 0

Views: 1333

Answers (2)

Adiii
Adiii

Reputation: 60164

As mention on the docker hub of php you can see by default it contain only redis redis xdebug is enabled.

Some extensions are not provided with the PHP source, but are instead available through PECL. To install a PECL extension, use pecl install to download and compile it, then use docker-php-ext-enable to enable it.

https://hub.docker.com/_/php/

You can use the same docker compose file just run a command on container boot up

  php:

image: php:7.1-fpm
command:docker-php-ext-install mysqli
volumes:
  - ./.code:/var/www/html  

Ater installation you can check

php -m

These are default modules in the latest docker images that you pulled.

    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

Upvotes: 3

Jakub Matczak
Jakub Matczak

Reputation: 15696

This error (could not find driver) means, that your PHP doesn't have pdo_mysql module loaded. You need to enable it or install first if it's not installed yet.

Upvotes: 1

Related Questions