You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LEMP环境下Laravel执行migrate报错:could not find driver 求助

Fixing "could not find driver" Error in Laravel 5.5 (PHP 7.2)

Hey there, that error you're hitting when running php artisan migrate is super common—it almost always means PHP doesn't have the MySQL/MariaDB extension installed. Laravel needs this driver to connect to your database, so let's get this sorted step by step:

1. Confirm the Missing Extension

First, let's verify the issue. Run this command in your terminal to list all enabled PHP modules:

php -m

Look for mysqli and pdo_mysql in the output. If neither shows up, that's definitely the root problem.

2. Install the PHP MySQL Extension

The installation command depends on your Linux distribution:

For Ubuntu/Debian Systems

Update your package list and install the extension with these commands:

sudo apt-get update && sudo apt-get install php7.2-mysql

Then restart your Nginx server and PHP-FPM to apply the changes:

sudo systemctl restart nginx
sudo systemctl restart php7.2-fpm

For CentOS/RHEL Systems

If you're using the Webtatic repository (a common source for PHP 7.2 on CentOS), run:

sudo yum install php72w-mysql

If you're using the official CentOS SCL repository, use this instead:

sudo yum install rh-php72-php-mysql

Then restart Nginx and PHP-FPM:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

3. Verify Installation & Retry Migration

Run php -m again—you should now see mysqli and pdo_mysql in the module list. After that, try your migration command once more:

php artisan migrate

Quick Configuration Double-Check

While you're at it, make sure your .env file has the correct database settings (matching the mamaput schema mentioned in your error):

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mamaput
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

If you edited the .env file, clear Laravel's configuration cache first:

php artisan config:clear

内容的提问来源于stack exchange,提问作者Patrick Obafemi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:52:24