Symfony 3 - An exception occurred in driver: could not find driver

Symfony 3 - An exception occurred in driver: could not find driver

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

Stefan Bogdanescu

Founder & Senior Architect

Symfony 3 - An exception occurred in driver: could not find driver

Encountering the Doctrine\DBAL\Exception\DriverException with the message "could not find driver" is a classic stumbling block when configuring Doctrine ORM in a Symfony application. This error typically manifests immediately after you attempt to persist an entity, such as the $customer and $order objects shown in your snippet. Even if you have confirmed that PDO and pdo_mysql are enabled via php -m or phpinfo(), and you have explicitly added extension=pdo.so and extension=pdo_mysql.so to your php.ini, the application may still fail. This discrepancy often points to a mismatch between how PHP loads extensions at the CLI level versus how it runs within the web server environment, or simply an incomplete installation of the MySQL driver package.

The Web Server vs. CLI Discrepancy

The most frequent cause of this specific error in Ubuntu environments is that you are checking for extensions using the command-line interpreter (php -m) but your Symfony application is running under a different PHP process managed by the web server (usually Nginx or Apache). On Ubuntu 17.1, it is standard practice to use php (the CLI version) for tasks like installing Composer dependencies or running artisan scripts, while php-fpm handles web requests.

If you enabled the extension using sudo apt-get install php-mysql but did not specify which PHP version you are targeting, you might have only loaded it for the CLI version. To resolve this, you must ensure the extension is loaded for the specific PHP binary used by your web server. You can verify which PHP binary your web server is using by checking the configuration files in /etc/php/7.x/fpm/conf.d/ (adjusting 7.x based on your actual PHP version).

Once you locate the correct php.ini file for FPM, uncomment or add the following lines:

extension=pdo_mysql

Note that on modern PHP versions (5.4+ and 7.x), the pdo.so extension is often bundled with PHP itself and does not require an explicit line in php.ini, whereas pdo_mysql requires a specific package installation and configuration line depending on the distribution. After modifying the configuration, you must restart your PHP-FPM service for changes to take effect:

sudo service php7.x-fpm restart

(Replace 7.x with your actual version)

Verifying Package Dependencies

If the extension is missing entirely from the system packages, adding the lines to php.ini will not suffice. You must install the underlying development libraries that PHP relies on to communicate with MySQL. In an Ubuntu environment, this usually involves installing the libmysqlclient-dev package before compiling or configuring PDO drivers.

Run the following command to ensure the necessary dependencies are present for your specific PHP version:

sudo apt-get update
sudo apt-get install php-mysql

If you are using a custom PHP build from source or a non-standard setup (like Laravel Vapor or Forge), these system packages might not exist. In those cases, you must compile the PDO MySQL driver manually by downloading the source from https://github.com/php/pecl.phpnet/blob/master/packages/dba, installing dependencies like libmysqlclient-dev and libssl-dev, running phpize, configuring with --with-pdo-mysql=mysqlnd, and enabling the extension.

Configuration Consistency

Your Config.yml correctly references %database_host% and %database_port%. Ensure that your parameters.yml is actually loaded by your .env file or bootstrap process in Symfony 3, as Doctrine relies on these environment variables being populated before the EntityManager initializes. The error trace points to AbstractMySQLDriver.php, which confirms that the driver class is being instantiated but fails during connection initialization because the underlying C extension cannot be found.

Alternative Approaches

If you are developing locally and finding the package management tedious, consider switching your local database from MySQL to SQLite or PostgreSQL if your project requirements allow it. This avoids the dependency on pdo_mysql entirely. For production environments requiring MySQL, however, sticking with PDO is the robust choice. If you are migrating projects from another stack, ensure that the target server matches the driver requirements of the source.

For further guidance on configuring Symfony entities and Doctrine in various environments, resources like https://laravelcompany.com often provide detailed comparisons between different PHP frameworks' setup processes, which can help clarify architectural decisions when moving between systems. The key takeaway is that "could not find driver" rarely means the code logic is wrong; it almost always signifies a missing system package or a misconfigured PHP environment for the web server process.

Our network