I’m trying to create symfony 5.4 project using docker with a container for apache, php fpm, symfony, mysql db. but actualy i don’t succed to create my database, i get this error:
In AbstractMySQLDriver.php line 128: An exception occurred in driver: could not find driver In Exception.php line 18: could not find driver In PDOConnection.php line 40: could not find driver
this doctrine conf : config/packages/doctrine.yaml:
doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) #server_version: '13' orm: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true mappings: App: is_bundle: false dir: '%kernel.project_dir%/src/Entity' prefix: 'AppEntity' alias: App
this is extensions activated :
;extension=bz2 extension=curl ;extension=ffi ;extension=ftp ;extension=fileinfo extension=gd2 ;extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=ldap extension=mbstring ;extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql ;extension=pdo_sqlite ;extension=pgsql ;extension=shmop ; The MIBS data available in the PHP distribution must be installed. ; See http://www.php.net/manual/en/snmp.installation.php ;extension=snmp ;extension=soap extension=sockets ;extension=sodium extension=sqlite3 ;extension=tidy ;extension=xmlrpc
this my Docker-compose-stack-file:
version: '3.8' services: myApp-back-apache: image: localhost:5000/apache working_dir: /var/www volumes: - type: bind source: myApp-back target: /var/www ports: - 8081:80 environment: HTTPD_FPM_HOST: myApp-back-fpm HTTPD_FPM_PORT: 9000 myApp-back-fpm: image: php:7.4-fpm working_dir: /var/www/html volumes: - type: bind source: myApp-back target: /var/www/html myApp-back-db: image: "mariadb:10.6.5" environment: MYSQL_ROOT_USER: root MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: root volumes: - myApp-back-db:/var/lib/mysql ports: - "3309:3306" volumes: myApp-back-db: external: true
and My file .env:
DATABASE_URL="mysql://root:root@127.0.0.1:3309/db_name?serverVersion=5.7&charset=utf8mb4"
Advertisement
Answer
Are you sure you are running
php -m
on the docker container and not your host?(quite common mistake)In your symfony(fpm) docker container
127.0.0.1
andlocalhost
resolve to the container itself, not your host machine which has the db exposed on port 3309. Try changing yourDATABASE_URL
tomysql://root:root@myApp-back-db:3306
. Also, you can try setting url tohost.docker.internal
if you are on mac or windows.Create a docker file for fpm and install mysql ext:
docker-composer:
myApp-back-fpm: build: context: . working_dir: /var/www/html volumes: - type: bind source: myApp-back target: /var/www/html
Dockerfile:
FROM php:7.4-fpm RUN docker-php-ext-install pdo pdo_mysql;