[Solved] An Exception Occurred in The Driver: Could Not Find Driver
Activate the extensions or add the absolute path for a quick fix
3 min. read
Published on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
Key notes
- To fix An exception occurred in the driver: could not find driver, check the file names and paths, and install MySQL.
- Keep reading to find more verified solutions from our experts!
When running a Symphony app, users often get the An exception occurred in the driver: could not find driver error followed by the configured driver path. This is the case when the app uses the MySQL database.
The error usually appears when MySQL is not installed, you have incorrect file names, critical files are missing or stored in the wrong directory, or the required extensions are not installed or activated.
How do I fix the An exception occurred in the driver error?
Before we start with the slightly complex solutions, try these quick ones:
- Make sure you have saved the .env.local with a period (.) before the file name and that it’s stored in the app/ directory. Both app/.env and app/.env.local need to be stored in the same directory.
- Run the command inside the PHP container instead of the PC’s default terminal.
- Ensure the php.ini is named as such and not php.ini-prod after editing.
1. Install MySQL and its drivers
Install MySQL by running the following command in the terminal: sudo apt install php-mysql
For those running Linux, use this command to install the missing extensions: sudo apt-get install php-mysql php-pdo
If you use Docker, use this command to install the MySQL drivers: RUN docker-php-ext-install pdo pdo_mysql
2. Activate the extensions
In the php.ini file, add the path where xampp installed the extensions next to extension_dir. For instance, it could be: C:\xampp\php\ext
Now, activate the following extensions:
- extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=mbstring
extension=exif
extension=mysqli
extension=pdo_mysql
extension=pdo_sqlite
3. Add the absolute path
Add the absolute path (could be different in your case) to extensions_dir with the following command: extension_dir = "c:\php5\ext"
Once done, restart the web server and check for improvements.
4. Replace 127.0.0.1 with Localhost
If you are getting the An exception occurred in the driver: could not find driver error while running: php bin/console doctrine:database:create
orsymfony console doctrine:database:create
Replace 127.0.0.1 with localhost in DATABASE_URL. It finally becomes: DATABASE_URL="mysql://db_user:db_password@localhost:3306/db_name?serverVersion=5.7&charset=utf8mb4"
The solution has been confirmed to work by many users. You should try this even if both [email protected] and root@localhost are stored in the MySQL user table.
5. Reinstall PHP’s PostgreSQL and remove unused PHP versions
- Remove Symphony from the computer. Check the ~/.symfony directory or any other location where it may be stored.
- Now, run the following command to remove PHP’s PostgreSQL:
sudo apt-get --purge remove php-pgsql
- Remove the unused PHP version with this command (the version may differ in your case):
sudo apt-get purge 'php5.6'
- Use this command to install PHP’s PostgreSQL:
sudo apt-get install php-pgsql
- Finally, download Symphony from the official website for your operating system and check for improvements.
One of these solutions should have helped fix the An exception occurred in the driver: could not find driver error. Remember, the error may arise from trivial misconfigurations to major corruption, and you will have to tackle it appropriately.
Before you leave, learn how to install Apache on Windows 11 and prevent similar errors from arising!
For any queries or to share what worked for you, drop a comment below.
User forum
0 messages