我正在尝试运行我的Laravel 5.7应用程序但在尝试在我的页面中运行查询时始终会收到错误Could not find driver
。
这是我的.env代码的一部分:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
无论如何,我们使用MariaDB而不是使用mysql。我可以确认mariadb正在运行没有任何问题,因为如果我在终端中运行mysql -u root -p
,我可以连接到我的MariaDB。以下是成功登录MariaDB时的欢迎信息。
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.2.8-MariaDB MariaDB Server
运行phpinfo()
将返回此:
PDO support enabled
PDO drivers pgsql, sqlite
MySQL driver for PDO George Schlossnagle, Wez Furlong, Ilia Alshanetsky, Johannes Schlueter
MySQLi Zak Greant, Georg Richter, Andrey Hristov, Ulf Wendel
MySQLnd Andrey Hristov, Ulf Wendel, Georg Richter, Johannes Schlüter
但我可以确认我的/opt/rh/rh-php71/root/usr/lib64/php/modules
文件夹包含pdo_mysql.so
,pdo.so
,mysqli.so
和mysqlnd.so
而且我的/etc/opt/rh/rh-php71/php.d
文件夹包含30-pdo_mysql.ini
,它只包含一行,extension=pdo_mysql.so
那么为什么我的pdo mysql不运行?
事实证明我需要重启我的php-fpm。谷歌搜索和谷歌搜索,我仍然找不到我的php-fpm服务的确切名称,所以我做了sudo find | grep fpm
,发现我的php-fpm服务名称是rh-php71-php-fpm
所以我运行sudo service rh-php71-php-fpm restart
和sudo systemctl restart httpd
,现在mysql列在PDO驱动程序下,我可以成功运行我的应用程序。
说真的,为什么不同版本的Linux有不同的同名名称?
你可以从yum安装php mysql连接包
首先安装#yum install epel-release -y然后