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]
could not find driver (SQL: select * from information_schema.tables where table_schema = pmaramaldb and table_name = migrations)

[PDOException]
could not find driver

My .env file has:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=pmaramaldb

DB_USERNAME=user

DB_PASSWORD=密码

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

Enabling Extension Solution:

PDO is enabled

php.ini文件是自动生成的,我猜这是由Plesk制作的.文件开头写道:

; 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.

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

Installing php7.0-mysql Solution:

我还try 安装MySQL,以防:

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

莱恩多·利斯塔·德·帕奎特斯...赫乔

Creando árbol de dependencias

我不知道该怎么做.回声

php7.0-mysql is already the newest version.

没有现成的,没有现实化的,没有现实化的.

** SQL Lite Install Solution:**

我也try 过as question link说:sudo apt-get install php5-sqlite,结果是:

user@server:/var/www/vhosts/system/maramal.io/etc$sudo apt获取安装php5 sqlite

莱恩多·利斯塔·德·帕奎特斯...赫乔

Creando árbol de dependencias

我不知道该怎么做.回声

php5-sqlite is already the newest version.

没有现成的,没有现实化的,没有现实化的.

Composer Dump-autoload Solution:

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

运行命令php -i后:

PDO

PDO support => enabled

PDO drivers =>

...

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

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

PHP5.6.30-1+deb.苏里.组织~trusty+1(cli)

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提供

推荐答案

Apache使用的PHP和链接到命令行的PHP之间存在冲突.(老实说,这件事发生得更频繁).

通常要做的是:

which 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版本链接或复制到可执行路径:

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,还建议您:

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

这样,CLI将与Web服务器匹配.

Update:

如果如this answer中所述,如果您使用Ubuntu和多个可选的PHP安装,您可以:

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>

Laravel相关问答推荐

@vite指令在使用laravel vite构建后导致错误

使用MAATWebSite/EXCEL导入Exel时,不会创建Laravel模型

Laravel中如何动态更改路由链接?

如何在Vite和Rollup中完全禁用分块?

分页计数(*)查询问题

无法在 Laravel 项目中安装 @vitejs/plugin-vue

不能在 laravel 中使用控制器名称,必须使用命名空间

Laravel | 使用select查询

Laravel:在失败时处理 findOrFail()

Laravel 5.8 在从已清除的会话中单击注销后显示419 Page Expired

Laravel 5.4 中的自定义助手类

Laravel - 如何恢复本地存储符号链接并刷新

如何从 Laravel 中的 hasMany() 关系中获取所有结果?

使用数据库用户提供程序时如何在 Laravel 中创建密码重置方法

如何在 Laravel 中使用旧输入重定向?

如何仅在Blade模板存在时才包含它?

Laravel Eloquent - 加入表时防止覆盖值

Laravel 如何具体构建和判断 CSRF 令牌?

Laravel php artisan 产生错误

Eloquent的关系 - attach附加(但不保存)到 Has Many