Resolving PDO Driver Errors in Laravel on macOS with MAMP
Encountering a [PDOException] Could not find driver error during php artisan migrate is a classic deployment blocker, particularly when running a local development stack like MAMP PRO on macOS. While the error message suggests a missing driver, the root cause is almost invariably a mismatch between the PHP interpreter used by your web server and the extensions actually loaded in that specific runtime.
In the scenario described, the application configuration in config/database.php correctly points to MySQL:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
The immediate assumption is that the pdo_mysql extension is missing. However, a common pitfallâevident in attempts to fix this by adding extension=pgsql.so and extension=pdo_pgsql.so to php.iniâis modifying the wrong configuration file or the wrong PHP binary.
MAMP PRO often manages multiple PHP versions (such as the 5.4.4 mentioned in the environment). When you edit a system-wide php.ini, you might be editing the configuration for PHP-FPM or CLI, while your web server is running a different version of PHP that doesn't have those extensions installed at all. Adding PostgreSQL drivers to a setup intended only for MySQL is unnecessary bloat and does not solve the missing pdo_mysql issue.
To diagnose this accurately, you must inspect the actual environment where the error occurs. Run the following command in your terminal:
php -m | grep pdo
If pdo_mysql is absent from the output, the driver is indeed uninstalled or disabled for the specific PHP binary MAMP is using. Conversely, if pdo_mysql is present but you still see the error, check the database connection string. In your config/database.php, ensure that the driver key explicitly matches 'mysql'. A typo here, such as 'myqsl' or a missing quote, will cause Laravel to attempt to instantiate an unknown PDO driver, resulting in the same exception message.
Once you have confirmed the driver is missing in the target PHP environment (likely via MAMP's Preferences under the "PHP" tab), you need to install it. On macOS with MAMP, this usually involves installing the necessary packages or enabling the extension within MAMP's specific configuration directory rather than a global system php.ini.
If you are using Homebrew to manage your development tools alongside MAMP, be cautious about mixing PHP binaries. Ensure that the path to the PHP executable in your terminal matches the one MAMP is invoking. You can verify this by running:
which php
php -r "echo php_ini_loaded_file();"
The output of php_ini_loaded_file() must point to the php.ini located inside your MAMP installation folder (typically under /Applications/MAMP/Library/etc/). If it points elsewhere, you are likely using a different PHP version than the one serving your Laravel application.
After enabling or installing the pdo_mysql extension in the correct configuration file, restart the web server within MAMP and run php artisan migrate again. The migration should proceed if the driver is now correctly linked to the PHP binary executing the command.
For modern Laravel projects (version 4 being notably old), staying on outdated PHP versions like 5.4.4 introduces security risks and compatibility issues with newer packages. If your goal is long-term stability, consider upgrading to a supported PHP version compatible with your current Laravel version and ensuring all extensions are available in that newer runtime.
