Laravel 5.4 on PHP 7.0: PDO Exception - Could not find driver (MySQL)
You are encountering the PDOException because the PHP interpreter running your CLI commands is fundamentally mismatched with the environment described in your investigation. The error message could not find driver combined with a stack trace indicating a missing MySQL connection usually points to one of two things: the PDO extension isn't loaded, or more commonly, the specific driver for your database engine (MySQL/MariaDB) is absent.
In your logs, you confirmed that php7.0-mysql is installed and marked as the newest version. However, a critical detail in your php -i output reveals the actual culprit: your CLI interpreter is running PHP 5.6, not PHP 7.0.
PHP Version => 5.6.30-1+deb.sury.org~trusty+1
PHP 5.6.30-1+deb.sury.org~trusty+1 (cli)
This is a classic Plesk hosting scenario. Web requests are handled by the Apache/FastCGI process running PHP 7, but your php artisan commands are invoking a separate CLI binary that defaults to PHP 5.6. The package php7.0-mysql installs the driver for the PHP 7 interpreter, but it does not automatically install or enable the driver for the PHP 5.6 CLI process. Consequently, when you run php artisan migrate, the script uses PHP 5.6, which lacks the MySQL PDO driver required to connect to your database.
Verifying the Mismatch
Before attempting any configuration changes, you must confirm which PHP version is actually executing your commands. Run the following command in your terminal:
which php
php -v
If which php returns a path like /usr/bin/php5.6 or if -v confirms version 5.6, that is the source of the problem. The environment variable PATH might be prioritizing the older PHP binary over the new one, even though Plesk has configured Apache to use PHP 7 for HTTP requests.
Resolving the Driver Issue
Since you are on Ubuntu (likely Trusty given the PHP version), and assuming the system packages are managed via apt, you need to ensure the MySQL driver is installed for the specific PHP version being used by CLI.
If your goal is strictly to keep using PHP 5.6 for CLI (which is not recommended for Laravel 5.4 as it is end-of-life), you must install the matching package:
sudo apt-get install php5.6-mysql
However, the standard and most robust solution for a modern setup is to ensure your CLI uses PHP 7.0 or higher. If you have PHP 7.0 installed on the server, you can force the CLI to use it by updating your shell's PATH environment variable in your user profile (e.g., .bashrc):
export PATH=/usr/bin/php7.0:$PATH
After adding this line, restart your terminal session or run source ~/.bashrc, then verify the version again with php -v. Once the CLI is pointing to PHP 7.0, the existing php7.0-mysql package will satisfy the dependency, and the driver will be recognized.
Configuring Plesk Environment
If modifying your system path proves difficult, another approach within Plesk involves checking the "PHP Settings" for your specific domain or virtual host. In the Plesk interface under Tools & Settings -> PHP Settings, you can select PHP 7.0 as the active version for that site. This ensures that both web requests and associated CLI tools (if configured to use the site's PHP environment) utilize the correct interpreter with its corresponding drivers.
Conclusion
The error is not caused by a misconfiguration in your .env file or a missing database; it is strictly an environmental mismatch between the PHP version running your commands and the installed extensions. By aligning your CLI execution path to use PHP 7.0, you will immediately resolve the could not find driver exception and allow migrations to proceed successfully.
