接收PHP警告:模块' [模块名称]'已经在第0行加载了Unknown

时间:2016-02-24 03:33:24

标签: php mysql ubuntu pdo server

我在学习如何管理服务器的同时尝试学习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文件被解析了#34;所示:

/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

感谢。

1 个答案:

答案 0 :(得分:2)

也许是因为您尝试在PHP7之上安装php5-mysql。正如名称所说的那样是PHP5的扩展名。可能已经加载了PHP7的另一个扩展。因为您使用PHP7,所以请确保加载正确的PHP7扩展。尝试安装PHP7.0-mysql扩展,然后重新启动Web服务器。

$ sudo apt-get install php7.0-mysql