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

查看:51
本文介绍了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:从information_schema.tables中选择*,其中table_schema = pmaramaldb,table_name =迁移)

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

[PDOException]
找不到驱动程序

[PDOException]
could not find driver

我的 .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 = pmaramaldb

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árboldedependencias

Creando árbol de dependencias

Leyendo lainformationaciónde estado ... Hecho

Leyendo la información de estado... Hecho

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

0个实际值,0个安装年份,0个等级和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árboldedependencias

Creando árbol de dependencias

Leyendo lainformationaciónde estado ... Hecho

Leyendo la información de estado... Hecho

php5-sqlite已经是最新版本.

0个实际值,0个安装年份,0个等级和67个没有实际值.

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

Composer转储自动加载解决方案:

它也不起作用.我尝试了composer dump-autoload,但是没有用.

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

运行命令php -i后:

PDO

PDO

PDO支持=>启用

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,Zend Technologies版权所有(c)1999-2016

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

或以下内容也应该起作用.

or the following should also work.

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

还建议您是否希望能够手动安装mods

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将与您的Web服务器匹配.

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天全站免登陆