我正在学习如何管理服务器的同时学习Laravel和
PHP.我试图修复一个不同的问题,一个关于在尝试从sqlite数据库中读取时未找到PDO驱动程序的问题.
我的服务器运行的是PHP 7.0,实际上我使用本指南从5.5.9升级了它:
https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04
为了解决PDO驱动程序问题,我运行以下命令:
apt-get install php5-mysql
这不能解决问题,但现在每次运行PHP命令时,都会遇到以下文本:
PHP Warning: Module 'PDO' already loaded in Unknown on line 0
PHP Warning: Module 'calendar' already loaded in Unknown on line 0
PHP Warning: Module 'ctype' already loaded in Unknown on line 0
PHP Warning: Module 'exif' already loaded in Unknown on line 0
PHP Warning: Module 'fileinfo' already loaded in Unknown on line 0
PHP Warning: Module 'ftp' already loaded in Unknown on line 0
PHP Warning: Module 'gettext' already loaded in Unknown on line 0
PHP Warning: Module 'iconv' already loaded in Unknown on line 0
PHP Warning: Module 'Phar' already loaded in Unknown on line 0
PHP Warning: Module 'posix' already loaded in Unknown on line 0
PHP Warning: Module 'shmop' already loaded in Unknown on line 0
PHP Warning: Module 'sockets' already loaded in Unknown on line 0
PHP Warning: Module 'sysvmsg' already loaded in Unknown on line 0
PHP Warning: Module 'sysvsem' already loaded in Unknown on line 0
PHP Warning: Module 'sysvshm' already loaded in Unknown on line 0
PHP Warning: Module 'tokenizer' already loaded in Unknown on line 0
PHP Warning: Module 'zlib' already loaded in Unknown on line 0
我在网上发现了很多关于这个问题的文章,他们都说我只需要在php.ini文件中取消注释行.运行phpinfo()显示我加载的配置文件在这里:
/etc/php/7.0/apache2/php.ini
我转到那个文件,然后我搜索“extension =”,但我看到每个提及的扩展都已被注释掉了.见例子:
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
我在phpinfo()中看到了两件可能与某些事情有关的事情. “扫描此目录以获取其他.ini文件”
/etc/php/7.0/apache2/conf.d
“我解析的其他.ini文件”显示:
/etc/php/7.0/apache2/conf.d/10-opcache.ini, /etc/php/7.0/apache2/conf.d/10-pdo.ini, /etc/php/7.0/apache2/conf.d/20-calendar.ini, /etc/php/7.0/apache2/conf.d/20-ctype.ini, /etc/php/7.0/apache2/conf.d/20-exif.ini, /etc/php/7.0/apache2/conf.d/20-fileinfo.ini, /etc/php/7.0/apache2/conf.d/20-ftp.ini, /etc/php/7.0/apache2/conf.d/20-gettext.ini, /etc/php/7.0/apache2/conf.d/20-iconv.ini, /etc/php/7.0/apache2/conf.d/20-json.ini, /etc/php/7.0/apache2/conf.d/20-mysqli.ini, /etc/php/7.0/apache2/conf.d/20-pdo_mysql.ini, /etc/php/7.0/apache2/conf.d/20-phar.ini, /etc/php/7.0/apache2/conf.d/20-posix.ini, /etc/php/7.0/apache2/conf.d/20-readline.ini, /etc/php/7.0/apache2/conf.d/20-shmop.ini, /etc/php/7.0/apache2/conf.d/20-sockets.ini, /etc/php/7.0/apache2/conf.d/20-sysvmsg.ini, /etc/php/7.0/apache2/conf.d/20-sysvsem.ini, /etc/php/7.0/apache2/conf.d/20-sysvshm.ini, /etc/php/7.0/apache2/conf.d/20-tokenizer.ini, /etc/php/7.0/apache2/conf.d/20-zlib.ini
我不想再弄乱我的服务器,所以我想知道是否有人知道如何解决这些错误.我已经卸载了php5-mysql,没有按预期修复问题.作为奖励,如果有人知道如何在尝试读取sqlite数据库后正确修复以下PDO错误,那将是惊人的:
[PDOException]
could not find driver
谢谢.
最佳答案 也许是因为你尝试在PHP7之上安装php5-mysql.正如名称所说的那样是PHP5的扩展名.可能已经加载了PHP7的另一个扩展.因为您使用PHP7,所以请确保加载正确的PHP7扩展.尝试安装PHP7.0-mysql扩展,然后重新启动Web服务器.
$sudo apt-get install php7.0-mysql