简体   繁体   中英

PHP module is already loaded warning

Just noticed, that PHP throws warnings, when executed on the CLI:

php module is already loaded

$ php -v
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:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/sockets.so' - /usr/lib/php/20151012/sockets.so: undefined symbol: php_network_gethostbyname 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 7.0.3-5+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0RC4, Copyright (c) 2002-2016, by Derick Rethans

I know, how to prevent them -- simply remove extension={extname}.so from the /etc/php/7.0/cli/conf.d/{extname}.ini files. But:

Is removing of this line in the INI files a solution or just a workaround to avoid the warning messages? Can any side effects occur due to this? Why does it happen / What is the issue actually caused by?

You have probably loaded the shown extensions twice in your php.ini files.

You can search the folder /etc/php/7.0 where you will find php.ini files in its subfolders, most probably in :

  • /etc/php/7.0/cli/
  • /etc/php/7.0/apache2/

If you see some extension=something.so repeated twice in these php.ini files you can remove it from one or if still the warning shows remove from both.

PHP on Linux usually scans subfolders for more configuration files, which is what happened in this case.

Configuration File (php.ini) Path => /etc/php/7.0/cli Loaded
Configuration File => /etc/php/7.0/cli/php.ini Scan this dir for additional .ini files => /etc/php/7.0/cli/conf.d 
Additional .ini files parsed => 
  /etc/php/7.0/cli/conf.d/10-opcache.ini,
  /etc/php/7.0/cli/conf.d/10-pdo.ini,
  /etc/php/7.0/cli/conf.d/20-calendar.ini,
  /etc/php/7.0/cli/conf.d/20-ctype.ini,
  /etc/php/7.0/cli/conf.d/20-curl.ini,
  /etc/php/7.0/cli/conf.d/20-exif.ini,
  /etc/php/7.0/cli/conf.d/20-fileinfo.ini,
  /etc/php/7.0/cli/conf.d/20-ftp.ini,
  /etc/php/7.0/cli/conf.d/20-gettext.ini,
  /etc/php/7.0/cli/conf.d/20-iconv.ini,
  /etc/php/7.0/cli/conf.d/20-json.ini,
  /etc/php/7.0/cli/conf.d/20-mcrypt.ini,
  /etc/php/7.0/cli/conf.d/20-mongodb.ini,
  /etc/php/7.0/cli/conf.d/20-mysqli.ini,
  /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini,
  /etc/php/7.0/cli/conf.d/20-pdo_sqlite.ini,
  /etc/php/7.0/cli/conf.d/20-phar.ini,
  /etc/php/7.0/cli/conf.d/20-posix.ini,
  /etc/php/7.0/cli/conf.d/20-readline.ini,
  /etc/php/7.0/cli/conf.d/20-shmop.ini,
  /etc/php/7.0/cli/conf.d/20-sockets.ini,
  /etc/php/7.0/cli/conf.d/20-sqlite3.ini,
  /etc/php/7.0/cli/conf.d/20-sysvmsg.ini,
  /etc/php/7.0/cli/conf.d/20-sysvsem.ini,
  /etc/php/7.0/cli/conf.d/20-sysvshm.ini,
  /etc/php/7.0/cli/conf.d/20-tokenizer.ini,
  /etc/php/7.0/cli/conf.d/20-xdebug.ini,
  /etc/php/7.0/cli/conf.d/20-xsl.ini

Little walk through PHP scanned the folder /etc/php/7.0/cli/ and found a php.ini which told it there should be more configuration (ini) files in a subdirectory called conf.d and each module has its own ini file typically on Linux and in the later version of PHP.

To answer the question "Is removing of this line in the INI files a solution or just a workaround to avoid the warning messages?"

Honestly I like having the configuration for each module in a separate file, but you could remove the files in conf.d if you wish to configure the module in the php.ini file. I just find that it gets cluttered.

This happened to me when I installed the php-mbstring using sudo apt-get install php-mbstring and enabled extension=mbstring in my php.ini .

PHP look at two mbstring plugin. One in installed package, second in enabled package in php.ini

The solution is to disable the plugins in php.ini

;extension=bz2
;extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
;extension=mbstring

PHP is loading modules multiple times. Find and remove the extra php.ini file(s).

  1. Execute the following php file. It will print a lot of info about your php installation in a table:

.

<?php
phpinfo();
  1. In the table, find the entry for "Loaded Configuration File" . It will tell you where php.ini is located. Go on disk and rename it php.ini.bak .
  2. Restart the server and execute the file above once again. "Loaded Configuration File" will tell you where the other php.ini is located. That's the duplicate.
  3. Backup and remove the duplicate. Re-instate the original, and you should be good to to.

Check /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini. You should not load in each php.ini in this directories the extension xdebug.so. Only one php.ini should load it. PHP Warning: Module already loaded in Unknown on line 0

I had the same problem. I have updated my PHP Version and cleared off the issue.

For some reason, the problem originated because of an incoherent status of the composer.lock file. After a composer update (and of course running all my unit-tests to ensure nothing was broken), the error was gone and the composer run was clean.

just a piece of hint for those people who landed on this page.

  • check the configuration files loaded with phpinfo();
  • check the configuration files loaded in terminal php -i command check both php.ini files above. only uncomment/enable the intl extension at php.ini shown at phpinfo() and comment/disable the line code in php.ini file shown by php -i The one which used for php configuration is the one from phpinfo()
  • don't forget to restart the webserver and php in my case I am using nginx and php 7.4. "sudo systemctl restart nginx" "sudo service php7.4-fpm restart"

只需从 cpanel 降级您的 PHP 版本!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM