PHP 7.0 上的 Laravel 5.4:PDO 异常 - 找不到驱动程序 (MySQL) [英] Laravel 5.4 on PHP 7.0: PDO Exception - Could not find driver (MySQL)

查看:38
本文介绍了PHP 7.0 上的 Laravel 5.4:PDO 异常 - 找不到驱动程序 (MySQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Ubuntu 14.04(带有 Plesk 12.5.30 的 VPS)上有一个 Laravel 5.4 项目.创建数据库并使用所需信息设置 .env 文件后,我运行 php artisan migrate 并抛出异常:

I have a Laravel 5.4 project on my Ubuntu 14.04 (VPS with Plesk 12.5.30). After creating the database and setted up the .env file with required information I ran php artisan migrate and exceptions were thrown:

[Illuminate\Database\QueryException]
找不到驱动程序 (SQL: select * from information_schema.tables where table_schema = pmaramaldb and table_name = migrations)

[Illuminate\Database\QueryException]
could not find driver (SQL: select * from information_schema.tables where table_schema = pmaramaldb and table_name = migrations)

[PDOException]
找不到驱动

我的 .env 文件有:

DB_CONNECTION=mysql

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_HOST=127.0.0.1

DB_PORT=3306

DB_PORT=3306

DB_DATABASE=pmaraldb

DB_DATABASE=pmaramaldb

DB_USERNAME=用户

DB_USERNAME=user

DB_PASSWORD=密码

DB_PASSWORD=password

我已经按照大部分指南来解决这个错误,但没有任何积极的结果:

I've followed most of the guides to solve this error and there wasn't any positive results:

启用扩展解决方案:

PDO 已启用

php.ini 文件正在自动生成,我猜这是由 Plesk 制作的.在文件的开头它说:

The php.ini file is being generated automatically, I guess this is made by Plesk. At the start of the file it says:

;注意!
;
;请勿修改此文件,因为它是自动生成的,
;因此,下次生成文件时,您所做的所有更改都将丢失.

; ATTENTION!
;
; DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
; SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

所以无论如何我都试过了.之后,我重新启动了 Apache,然后再试了一次……没有用.

So I've tried it anyway. After that I've restarted Apache and then tried again... Didn't work.

安装php7.0-mysql 解决方法:

我也试过安装 MySQL,以防万一:

I've also tried to install MySQL in case is not:

user@server:/var/www/vhosts$ sudo apt-get install php7.0-mysql

user@server:/var/www/vhosts$ sudo apt-get install php7.0-mysql

Leyendo lista de paquetes... Hecho

Leyendo lista de paquetes... Hecho

Creando árbol de Dependencias

Creando árbol de dependencias

Leyendo la información de estado... Hecho

Leyendo la información de estado... Hecho

php7.0-mysql 已经是最新版本了.

0 次实现,0 次安装,0 次消除 y 67 次没有实现.

0 actualizados, 0 se instalarán, 0 para eliminar y 67 no actualizados.

** SQL Lite 安装方案:**

** SQL Lite Install Solution:**

我也试过 问题链接说:sudo apt-get install php5-sqlite 结果是:

I've also tried as question link says: sudo apt-get install php5-sqlite and the result was:

user@server:/var/www/vhosts/system/maramal.io/etc$ sudo apt-get install php5-sqlite

user@server:/var/www/vhosts/system/maramal.io/etc$ sudo apt-get install php5-sqlite

Leyendo lista de paquetes... Hecho

Leyendo lista de paquetes... Hecho

Creando árbol de Dependencias

Creando árbol de dependencias

Leyendo la información de estado... Hecho

Leyendo la información de estado... Hecho

php5-sqlite 已经是最新版本了.

0 次实现,0 次安装,0 次消除 y 67 次没有实现.

0 actualizados, 0 se instalarán, 0 para eliminar y 67 no actualizados.

Composer Dump-autoload 解决方案:

也没有用.我试过 composer dump-autoload 但没有用.

It didn't work either. I've tried composer dump-autoload and it didn't work.

运行命令php -i后:

个人信息保护

PDO 支持 => 启用

PDO support => enabled

PDO 驱动程序 =>

PDO drivers =>

...

PHP 版本 => 5.6.30-1+deb.sury.org~trusty+1

PHP Version => 5.6.30-1+deb.sury.org~trusty+1

好吧,我不确定这是否与错误有关,但是运行 php -v 显示的版本是:

Well, I am not sure if this has anything to do with the error, but the version shown by running php -v is:

user@server: ~/path$ php -v

user@server: ~/path$ php -v

PHP 5.6.30-1+deb.sury.org~trusty+1 (cli)

PHP 5.6.30-1+deb.sury.org~trusty+1 (cli)

版权 (c) 1997-2016 The PHP Group

Copyright (c) 1997-2016 The PHP Group

Zend Engine v2.6.0,版权所有 (c) 1998-2016 Zend Technologies
使用 Zend OPcache v7.0.6-dev,版权所有 (c) 1999-2016,由 Zend Technologies

Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

推荐答案

Apache 使用的 PHP 与链接到命令行的 PHP 之间存在冲突.(说实话,这种情况发生得更频繁).

There's a conflict between the PHP that is used by Apache and the PHP that is linked to the command line. (It happens more often that it should to be honest).

通常的做法是:

which php

这会告诉您在命令行中运行时将执行哪个 php.例如/usr/bin/php

This tells you which php will be expecuted when running in the command line. e.g. /usr/bin/php

mv /usr/bin/php /usr/bin/php.old

然后将正确的 PHP 版本链接或复制到可执行路径:

Then link or copy the correct PHP version to an executable path:

ln -s /path/to/php/bin/php /usr/bin/php

或以下也应该有效.

cp /path/to/php/bin/php /usr/bin/php

如果您希望能够手动安装模组,也建议:

Also suggested if you want to be able to manually install mods:

ln -s /path/to/php/bin/phpize /usr/bin/phpize
ln -s /path/to/php/bin/php-config /usr/bin/php-config

这样您的 CLI 将匹配您的网络服务器.

This way your CLI will match your webserver.

更新:

如果如此答案中所述,如果您将 Ubuntu 与多种 PHP 替代安装一起使用,您可以执行以下操作:>

If as noted in this answer if you are using Ubuntu with multiple alternative installations of PHP you can do:

sudo update-alternatives --set php /usr/bin/php<version>
sudo update-alternatives --set phar /usr/bin/phar<version>
sudo update-alternatives --set phar.phar /usr/bin/phar.phar<version> 
sudo update-alternatives --set phpize /usr/bin/phpize<version> 
sudo update-alternatives --set php-config /usr/bin/php-config<version>

这篇关于PHP 7.0 上的 Laravel 5.4:PDO 异常 - 找不到驱动程序 (MySQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆