7

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?

automatix
  • 14,018
  • 26
  • 105
  • 230

8 Answers8

8

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.

Anurag Kumar
  • 1,355
  • 11
  • 11
5

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.

Zanna
  • 205
  • 5
  • 13
Philip Rollins
  • 1,271
  • 8
  • 19
  • Thank you for the answer! But you're assuming, that the `extension={exname}.so` statements are in the INI includes AND in the main `php-ini`. Right? But it's not like this -- the `php.ini` doesn't consist anything for loading extensions. It's why I'm wondering, that PHP tries to load them twice. – automatix Jul 04 '16 at 11:23
  • Can you zip or tar /etc/php/7.0 and upload it. PHP uses different ini files for cli/cgi/apache/nginx/fpm. I can run it on my linux distro and hopefully fix this problem which has become personal :p – Philip Rollins Jul 04 '16 at 21:42
  • Thank you for still trying to help me & sorry for the delay! I zipped the entire `/etc/php` directory. (Of course all the symlinks has become independent files.) You can download it [here](https://www.dropbox.com/s/73xnnwz6tuve62i/php.zip?dl=0). – automatix Jul 06 '16 at 08:39
  • The /cli/php.ini file isn't in the archive. Reading through some posts online, it sounds like PHP is compiled with PDO already (my configuration uses it as an extension on php 5) so there's no reason to load it as an extension. However I was unable to find confirmation of this on the PHP website. – Philip Rollins Jul 07 '16 at 13:51
  • Sorry, I removed the `php.ini` for CLI to test something and then forgot to restore it. Added it now again to `/etc/php/7.0/cli/` and to the archive in Dropbox. I also added the output of `php -i` as a file (`php-i.txt` in the archive's root). – automatix Jul 07 '16 at 14:21
  • I see no issues with the configuration files, I'd report this as a bug [here](https://bugs.php.net/). Hopefully they'll be able to guide you in the right direction. – Philip Rollins Jul 08 '16 at 08:28
3

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.
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165
  • Thank you, but it didn't work. Look: **1.** `php -r 'phpinfo(); echo PHP_EOL;' | grep "php.ini"` -- output: line1 `Configuration File (php.ini) Path => /etc/php/7.0/cli`, line2 `Loaded Configuration File => /etc/php/7.0/cli/php.ini`. **2.** `mv /etc/php/7.0/cli/php.ini ~/Desktop/`. **3.** `service php7.0-fpm restart`. **4.** `php -r 'phpinfo(); echo PHP_EOL;' | grep "php.ini"` -- output: onlie one line `Configuration File (php.ini) Path => /etc/php/7.0/cli`. And all the `PHP Warning: Module 'gettext' already loaded in Unknown on line 0` stuff is still here. – automatix Jul 04 '16 at 11:32
3

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
Player1
  • 2,878
  • 2
  • 26
  • 38
0

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

Community
  • 1
  • 1
kenai37
  • 1
  • 4
  • delete this: zend_extension="/usr/lib/php5/20******/xdebug.so" xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 – kenai37 Nov 16 '16 at 02:48
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.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
0

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"
Christian Igay
  • 25
  • 2
  • 10
-1

Just downgrade your PHP version from the cpanel!

  • Please add some further explanation to your answer such that others can learn from it. What makes you think that cpanel is involved after all? – Nico Haase Aug 15 '20 at 21:00