Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP loads the same extension twice at start-up

ErrorPHP Warning: Module already loaded in Unknown on line 0

Short answer

PHP read two ini lines that load the same extension, so it warned at start-up (hence 'Unknown on line 0'). Run php --ini to see every ini file PHP parsed, search them for the extension name, and keep one line. The usual double is php.ini plus a file in the scan directory.

  • Applies to PHP 8.3, PHP 8.4, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which ini files it parsed, then search all of them for the extension named in the warning.

    php --ini
    php --ini | grep -oE '/[^ ,]+\.ini' | xargs grep -n "intl"
  2. 2Match what you see, then jump to its fix

    1. 1php --ini lists the main php.ini and, under 'Additional .ini files parsed', a second file that also has the same extension= line.php.ini and a scanned ini file both load the extensionFix
    2. 2The warning appears only in one environment (a shell, a container, a service) that sets PHP_INI_SCAN_DIR, and php --ini lists the scan directory more than once or lists two copies of the same ini file.The same directory is scanned twice through PHP_INI_SCAN_DIRFix

What does the error look like?

  • PHP Warning: Module already loaded in Unknown on line 0

Cause 1 of 2

php.ini and a scanned ini file both load the extension

1Check

After the main file, PHP scans the configured directory and loads every .ini file in it in alphabetical order. An extension line in php.ini and another in one of those files loads it twice.

php --ini
php -r "var_dump(php_ini_scanned_files());"

2Fix

Keep one of the two lines. Comment out the line in the file you do not want to keep, with a semicolon at the start.

; php.ini
;extension=intl

3Verify

Run PHP again. The warning is gone and the extension is still loaded.

php -v
php -m | grep -i intl

Confirmed by php.net

Did this fix it?

Cause 2 of 2

The same directory is scanned twice through PHP_INI_SCAN_DIR

1Check

PHP_INI_SCAN_DIR replaces the compile-time scan directory. A blank entry in it makes PHP scan the compile-time directory as well, so a folder can be read twice, or two folders can each hold a file that loads the extension.

echo "$PHP_INI_SCAN_DIR"
php --ini

2Fix

Set PHP_INI_SCAN_DIR to the folders you really want, without a blank entry (no leading or trailing colon) and without the folder listed twice. Then remove duplicate ini files.

export PHP_INI_SCAN_DIR=/usr/local/etc/php.d

3Verify

Run php --ini again and check that every ini file is listed once.

php --ini

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Add each extension in exactly one file, and let your package manager own the scan directory.
  • After installing a PHP build or a panel, run php --ini and read the list once.
  • Keep CLI and FPM ini files in mind: they can differ, so check the one that prints the warning.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.