How to fix Laravel PDOException Could Not Find Driver error

How to fix Laravel PDOException Could Not Find Driver error

While working on the laravel application sometimes we got an error like PDOException Could Not Find Driver error. Here, we will discuss about the solution to fix “could not find driver” or after artisan migration running you got error “Class ‘Doctrine\\DBAL\\Driver\\PDOMySql\\Driver’ not found”.

Solution 1: If you do not have mysql/postgresql php module installed in your system

If you got this error then first thing you will need to check if you have mysql/postgresql php module installed in your system or not. 

Note: mysql/postgresql php module installation depends on your requirement or choice what database you want to use.

Install mysql php module:

For installing mysql php module, you will need to run the following command in your terminal.

sudo apt-get install php-mysql

or if you using php version other than latest version then run the command with specific version like below command.

sudo apt-get install php7.2-mysql

Install postgresql php module:

Run the following command to install postgresql php module.

sudo apt-get install php7.1-pgsql or sudo apt-get install php7.2-pgsql or sudo apt-get install php7.3-pgsql


After installing the above php module, you will also need to follow solution 2 to enable pdo_mysql extension.

Solution 2: If you do not have enable pdo_mysql extension

So here, for enabling pdo_mysql, the first thing have to find php.ini file.

You can find php.ini path via phpinfo() . Now open this php.ini file and uncomment following lines of if not available then add .

;extension=php_pdo_mysql.dll
;extension=pdo_mysql.so

For uncommenting you just need to remove semi colon (;) from front of these lines like below.

extension=php_pdo_mysql.dll
extension=pdo_mysql.so

Then, restart your Apache server.

If this issue comming after running php artisan migrate command, then after doing the above things, run this command again, hopefully this issue would be resolved.

You can also read the article to add column in laravel existing table through migration by clicking on the link below.

How to add column in laravel existing table through migration