If you looking to solve “Could not find driver” error while you working in Laravel web development then firstly you need to understand this error and why its occur so without any more wait lets dive to solution

What is “Could not find driver” Error ?

This error occurs when the system cannot connect to the database with the provided configuration in .env or config/database.php in Laravel. A database driver is necessary for communication between a Laravel application and a database, facilitating efficient data exchange. If the application cannot locate the driver or if incorrect configurations are set, this issue arises.

not found illustration

Ways to solve “Could not find driver” Error

I explain you 5 effective method that help you to resolve this error.

Clear Application Cache

Try to clear application cache. you can do by running below artisan command

php artisan optimize:clear

This command will clear all application cache including config and views.

laravel optimize clear command

Restart Web Server

If you trying to change in php configuration without restarting web server. that’s why you may facing issue so restart your web server first and try again to resolve error

if you using XAMPP in Windows then stop apache service and start again.

stop server in xampp

If you using valet in windows or linux

valet restart

if you using linux and ngnix

sudo systemctl restart nginx

Validate DB config

open your .env and there is 6 variable to change in configuration double check everything is proper given. this configuration is case sensitive so must be sure you entered exact values

env database config

Enable PDO Extension

Before you taking any action check that you have enabled PDO extension. go to public/index.php add phpinfo(); as show below

add phpinfo in index.php

Start the Laravel application you will get below page and find “PDO” if you see result like below then you don’t need to install and if you could not able to find then you need to install PDO php extension

PDO in phpinfo

install PDO extension in linux by following command

sudo apt-get install php*-mysql 

where * is a version name of php like  7.1, 7.2,8.0,8.1 change as per your system php version.

For Windows follow below steps

Step 1 : Open php.ini from xampp control panel

Step 2 : find pdo_mysql in file by search

remove semicolon (;) in that line and save it and restart Apache service from xampp control panel.

Update PHP Version

The “Could Not Find Driver” error can getting if you using an outdated version of PHP or corrupted current version in your system so I suggest you to upgrade your PHP version. this method just not fix this error but increase security and perfomance of your laravel application. for updating your PHP installation use package managers like apt-get for Ubuntu or through manual installations for other platforms.

could not find driver solved

To prevent this error in the future

  • Make your OS & php version up to date with new release to fix bugs.
  • Clear cache after you change anything in config or env
  • Restart web server after you change in php configuration or server file

Categorized in:

Laravel,

Last Update: July 30, 2024

Tagged in:

, ,