Laravel 5.4 on PHP 7.0: PDO exception - driver could not be found (MySQL)

I have a Laravel 5.4 project on my Ubuntu 14.04 (VPS with Plesk 12.5.30). After creating the database and file settings .env with the necessary information, I ran php artisan migrateand were granted an exception:

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

[PDOException]
could not find a 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 = password

, , :

:

PDO

php.ini , , Plesk. :

; !
;
; , ,
; , .

. Apache ... .

php7.0-mysql :

MySQL , :

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

Leyendo lista de paquetes... Hecho

Creando árbol de dependencias

... Hecho

php7.0-mysql .

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

** SQL Lite: **

, : 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

Creando árbol de dependencias

... Hecho

php5-sqlite - .

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

- :

. composer dump-autoload .

php -i php -i:

PDO

PDO =>

PDO =>

...

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

, , - , , php -v:

@: ~/ $ php -v

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

Copyright (c) 1997-2016 The PHP Group

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

+23
10

PHP, Apache, PHP, . ( ).

:

which php

, php . /usr/bin/php

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

PHP :

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

.

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

, :

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

, CLI -.

:

, , 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>
+12

, php7-mysql

sudo apt install php7.0-mysql
+37

, ubuntu 17.10, Laravel 5.5.

$sudo apt install php7.1-pdo php7.1-mysql

enter image description here

enter image description here

, ,

+18

, . :

1)

php -ini

php.ini.

2) php.ini vim .

vim/etc/php.ini

, /etc/php.ini - php.ini. .

3) find; extension = php_pdo_mysql.dll , (;)

4) php.ini/s

** 5) -, .

sudo systemctl restart apache2

** 6) .

php artisan migrate

, .

+10

php artisan cache:clear
php artisan config:clear  

Apache. .env

+3

.

ubuntu: mysql.

sudo apt-get install php5.6-mysql/php7.2-mysql

.

:

sudo apt-cache search drivername
+3

, ... , , php 7.3 - , , php 7.2, ...

+2

php artisan cache:clear

php artisan migrate:refresh

+1

, , PHP- :

PHP (5.6 by sury.org) PHP- "/usr/bin/php", PHP-, , Plesk, :

/opt/plesk/php/5.2/bin/php -v
/opt/plesk/php/5.3/bin/php -v
/opt/plesk/php/5.4/bin/php -v
/opt/plesk/php/5.5/bin/php -v
/opt/plesk/php/5.6/bin/php -v
/opt/plesk/php/7.0/bin/php -v
/opt/plesk/php/7.1/bin/php -v

PHP- PHP (7.0 7.1, sury.org MAIN ppa PHP https://launchpad.net/~ondrej/+archive/ubuntu/php):

/usr/bin/php7.0 -v
/usr/bin/php7.1 -v

PHP -m -i ():

/opt/plesk/php/7.0/bin/php -m
/opt/plesk/php/7.0/bin/php -i
or
/usr/bin/php7.0 -m
/usr/bin/php7.0 -i

"", , , PHP ():

/opt/plesk/php/7.0/bin/php composer-setup.php
or
/usr/bin/php7.0 composer-setup.php

"":

/opt/plesk/php/7.0/bin/php composer.phar AND-ADDITIONAL-STRINGS/OPTIONS-TO-BE-INCLUDED
or
/opt/plesk/php/7.0/bin/php composer.phar AND-ADDITIONAL-STRINGS/OPTIONS-TO-BE-INCLUDED
0

Linux

PHP, :

php -v

, , , 7.1, ,

sudo apt-get install  php7.1-sqlite     //for laravel testing with sqlite
sudo apt-get install  php-mysql         //for default mysql
sudo apt-get install  php7.1-mysql      //for version based mysql 
sudo apt-get install  php7.1-common     //for other necessary package for php

apache2

sudo service apache2 restart
0

Source: https://habr.com/ru/post/1015892/


All Articles