3

I've seen a few similar questions to this one, but they seemed to be primarily addressing different environments than what I am using, so I hope this isn't a repeat.

I am trying to do a test migration in Laravel 4.2 on my local server using XAMPP on Windows 7. When I try to run php artisan migrate, I get the error:

  [PDOException]
  could not find driver



migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--pac
kage[="..."]] [--pretend] [--seed]

Most other suggestions I've seen are in regards to the php.ini file, but I do have the necessary line uncommented:

extension=php_pdo_mysql.dll

And it appears to be running when I view my phpinfo():

                 mysqlnd
...
API Extensions          mysql,mysqli,pdo_mysql


                 pdo_mysql
PDO Driver for MySQL    enabled
Client API version      mysqlnd 5.0.11-dev - 20120503 - $Id: 
                        bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $

My only thought is that it might be an issue with my running XAMPP on ports 81 and 3307 instead of the default 80 and 3306 (although I believe I do have XAMPP's config files correctly configured, since I've been able to run other applications fine on these ports). Are there any other Laravel config files I might have missed though?

Edit 11/15 I see that there was a similar question asked here, but for what it's worth it appears that that error for that user had occurred after the installation process (it appeared to have been resolved through Laravel instead of through the php.ini file). This specific problem appears to have been related to the installation process itself, and appears to have help at least a few people that also were unable to find the specific answer in other versions of the question.

Community
  • 1
  • 1
cchapman
  • 3,269
  • 10
  • 50
  • 68
  • *I know this is old, but for the sake of keep alive:* Check your `Default Database Connection Name` it must be `'default' => 'mysql',` – Michel Ayres Jun 29 '15 at 11:23
  • For me the issue was Xampp version. The project i was working on required php7.4 and supported mysql version. But i installed the latest xampp. So after i installed xampp 7.4 everything worked smoothly. – Rakib Uddin Nov 24 '22 at 05:48

3 Answers3

9

So it did turn out to be a problem with the PATH settings. Thank you very much @ykbks. The link provided wasn't quite clear on how to diagnose it though, so just to expand on that in hopes it helps someone in the same position, from the command line I ran

C:\>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         (none)        <<Problem
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

So I kept changing the php.ini file that wasn't being seen by the system. I added XAMPP's php folder to the PATH and the migrate ran perfectly.

cchapman
  • 3,269
  • 10
  • 50
  • 68
  • Oh yes ! This post helped me a lot ! Just a remark : think to restart the computer after added the PATH setting – w3spi Oct 29 '15 at 19:24
  • Nice one. I had PHP installed when I set up Composer, then when I installed XAMPP and updated the php.ini file (for XAMPP), I couldn't figure out why it wasn't working. My global path was still pointing to C:\php rather than C:\xampp\php. – Matt Kieran May 20 '16 at 23:50
  • Happened to me too. Thanks :) –  Oct 12 '17 at 22:00
  • This is the reason. The commands you write in the command line is using another php package then Xampp provides. So, you must enable the php_pdo extension in the file where "php --ini" shows as "Loaded Configuration File". This solved my problem. Thank you @cchapman – mdikici Sep 29 '21 at 15:08
2

I had this error using Laravel 5.1 on Linux Ubuntu 15.10 with php5-fpm and NGINX. Seems like the problem comes due to missing PHP module. I resolved this installing on my system php5-mysql. Simply run:

sudo apt-get install php5-mysql

On Windows this can be fixed I hope including the MySQL module in php.ini file. On XAMPP this should be included by default.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Todor Todorov
  • 2,503
  • 1
  • 16
  • 15
1

This can happen for a Number of reasons. Either the Default DB type is not set (config/database.php), or the Extension is not enabled, or you HAVE enabled the extension but have NOT restarted XAMPP, or the PATH settings under environment settings are not properly defined.

I suggest you check out this answer which may solve the issue: https://stackoverflow.com/a/25336292/2745485

Regards.

Yousof K.
  • 1,374
  • 13
  • 23