Symfony: An exception occured in driver: could not find driver with mysql

Symfony: An exception occured in driver: could not find driver with mysql

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Symfony: An exception occured in driver: could not find driver with mysql

When running a Symfony application on Windows while targeting a MySQL database hosted in Docker, the error An exception occured in driver: could not find driver is almost exclusively an issue of missing or misconfigured PHP extensions rather than a network connectivity problem. The specific configuration you shared shows a classic setup for a cross-platform deployment, but the distinction between the operating system hosting your code and the container running your database often leads to confusion regarding which environment actually needs the drivers installed.

In your config.yml, you correctly mapped the Doctrine DBAL driver to pdo_mysql. This tells Symfony's ORM layer how to construct the PDO connection string. However, PDO is merely a wrapper; it does not implement the MySQL protocol itself. It relies on an underlying extension to handle the actual communication with the server. On Linux-based systems, these extensions are often pre-installed via package managers like apt or yum. On Windows, however, PHP distributions like XAMPP or standalone installations do not always include these drivers by default, especially when targeting specific MySQL versions required by Docker containers.

The snippet from your php.ini file indicates that you have enabled php_mysqli.dll and php_pdo_mysql.dll. While enabling these in the configuration file is the correct logical step, on Windows, the physical presence of these .dll files in the PHP installation directory is a hard requirement. If the DLL files are missing, or if they were compiled against a different version of MySQL than what your Docker container provides, PDO will fail to initialize, resulting in the "could not find driver" exception.

A common pitfall in this scenario involves the distinction between system-level PHP and the PHP running within your project context. Since you are programming on Windows but using a Docker database, ensure that the PHP executable being invoked by your Symfony CLI or Composer commands is the one where you have explicitly enabled these extensions. Sometimes developers install extensions to a global XAMPP installation but run their application via a different PHP binary located in the vendor/bin folder or a specific project container.

If you are using PHP 7.4 or later, the situation can be slightly more nuanced. Many modern Docker images for PHP include PDO drivers as part of the core image, but if you are running your application code directly on Windows without Docker, you must manually verify that the php_mysqli.dll and php_pdo_mysql.dll files exist in your ext directory. You can confirm this by running the following command in PowerShell:

Get-ChildItem "C:\path\to\php-installation\ext" | Select-String -Pattern "mysqli|pdo_mysql"

If these files are absent, you will need to download the appropriate compiled DLLs from a trusted repository like PECL or enable them via Composer. Composer offers a convenient way to manage extensions without manually hunting for DLLs:

composer require symfony/pdo-mysql
# Note: This adds the driver logic but does not always install the dll on Windows automatically.

For a robust solution on Windows, consider using the php_mysqli.dll provided by the PECL repository that matches your exact PHP version and architecture (e.g., 64-bit vs 32-bit). Mismatched architectures are a frequent cause of silent failures or runtime errors in this context.

Additionally, verify that your Docker container's MySQL server is actually reachable from your Windows machine before assuming the driver is the culprit. You can test connectivity using a standalone PDO script:

<?php
try {
    $dsn = "mysql:host=your-docker-host;port=3306;dbname=your-db";
    $pdo = new PDO($dsn, 'user', 'pass');
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

If this script fails with a connection timeout or refusal, the issue lies in your network configuration, firewall settings, or Docker port mapping. If it succeeds but Symfony still throws the driver exception, the php.ini settings are definitely the bottleneck. Ensure that pdo_mysql is not commented out and that no conflicting extensions are loaded before PDO initializes.

For developers looking for streamlined setup guides specifically tailored to Windows environments with Laravel or Symfony projects, resources like https://laravelcompany.com can provide valuable context on managing dependencies across different OS architectures, though the core fix remains ensuring the physical DLLs match your PHP installation.

Our network