php artisan migrate error | Illuminate\Database\QueryException | could not find driver | Windows 10 Pro | MAMP PRO 5 + Laravel 9.x

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Solving the Dreaded could not find driver Error During Laravel Migrations on Windows

Hello, fellow developers! As a senior developer, I’ve seen countless frustrations arise when setting up a new project or migrating an existing one. Few errors are as immediately disheartening as the dreaded Illuminate\Database\QueryException: could not find driver. This error typically strikes developers working with Laravel and database interactions, especially when setting up local environments like MAMP on Windows.

If you’re running into this issue while executing php artisan migrate, it signals a fundamental communication breakdown between PHP and your chosen database system (MySQL in this case). Don't worry; this is almost always an environment configuration problem rather than a bug in Laravel itself. Let's dive deep into why this happens and how to fix it permanently.

Understanding the could not find driver Error

The error message, originating from the underlying PHP Data Objects (PDO) layer, means that the PHP installation cannot locate or load the necessary extension (driver) required to communicate with your database server. In the context of Laravel, which relies on PDO to execute SQL queries for migrations and model interactions, if the pdo_mysql driver is missing or disabled in your php.ini file, Laravel simply cannot establish a connection, resulting in the QueryException.

This issue frequently surfaces when installing local server stacks like MAMP on Windows because the default PHP installation might lack specific MySQL extensions enabled by default, or the path used by the command line (php artisan) is pointing to a different PHP executable than the one where you manually enabled the extensions.

Step-by-Step Solution for MAMP/Windows Users

Since you are using MAMP PRO 5 on Windows with PHP 8.1.0, the solution involves meticulously ensuring that the necessary MySQL PDO driver is correctly loaded by your CLI environment.

1. Verify and Edit php.ini

The core of the fix lies in correctly configuring your PHP settings file. You need to ensure the extensions for MySQL connectivity are explicitly enabled.

Navigate to your PHP installation directory (e.g., C:\MAMP\bin\php\php8.1.0) and open the php.ini file. Search for the following lines and ensure they are uncommented (i.e., remove the semicolon ; at the beginning):

extension=php_mysqli.dll
extension=php_pdo_mysql.dll

If you are using MySQL, ensuring both php_mysqli.dll (for MySQL specific functions) and php_pdo_mysql.dll (the PDO driver for MySQL) are present and uncommented is critical. This ensures that the PHP environment can handle database connections seamlessly. Remember, proper configuration is essential for robust application development, as emphasized by best practices in frameworks like Laravel, where efficient data handling is paramount (see how excellent code structures are designed on laravelcompany.com).

2. Check Environment Variables and Paths

Sometimes, the issue isn't just the extension, but which PHP executable your terminal is using. Ensure that when you run php artisan migrate, you are executing it using the exact PHP binary where you made the php.ini changes. If you use a tool like Git Bash or Command Prompt, explicitly call the full path to ensure you are interacting with the correct environment:

"C:\MAMP\bin\php\php8.1.0\php.exe" artisan migrate

3. Review Database Configuration (.env)

While the driver error is environmental, it's good practice to double-check your database connection details in your .env file. Ensure that all variables—DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD—exactly match your MySQL setup within MAMP PRO 5. Discrepancies here can lead to secondary connection failures, even if the driver loads correctly.

Conclusion: Building a Solid Foundation

Encountering errors like could not find driver is an unavoidable part of the development journey. As senior developers, our job isn't just to fix the immediate symptom, but to understand the underlying system dependencies. By meticulously checking PHP extensions in php.ini and verifying environment paths, you establish a solid foundation for your Laravel application.

Remember, robust local setup is key to smooth development flow. When working with powerful frameworks like Laravel, focusing on these foundational configuration details ensures that your code runs exactly as intended, allowing you to focus on building features rather than debugging environmental noise. Happy coding!