When working with multiple version of PHP installed via Homebrew, there’s a chance you’ll encounter error messages like this:
PHP Warning: Module 'imagick' already loaded in Unknown on line 0 PHP Warning: Version warning: Imagick was compiled against Image Magick version 1809 but version 1808 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
Granted, the version number may be different but the rest of the message will be the same. When I’ve experienced this, it’s when I’ve a set up like this:
- I have multiple versions of PHP installed (anything from the earliest build in 7 up to the latest version in 8),
- I swap among versions in my
~/.zshrc
file depending on the project, - When I attempt to run code that’s on an older version of PHP after installing and using the newer or latest version of PHP, I see the above error.
To fix this, there are two things you can do:
- Locate the version of the
php.ini
file for the version of PHP you’re currently using, - Update the
php.ini
file for the version to disable the version check on Imagick.
Module ‘imagick’ already loaded
First, locate the php.ini
version for the instance of PHP you’re running by entering the following command into the terminal:
php -r "phpinfo();" | grep php.ini
When you’re done, you should see something like this:
Configuration File (php.ini) Path => /opt/homebrew/etc/php/7.4 Loaded Configuration File => /opt/homebrew/etc/php/7.4/php.ini
Next, open the php.ini
file listed in the second entry and look for the line that contains the following:
extension="imagick.so"
Right under that, add the following:
imagick.skip_version_check=true
Next, run source ~/.zshrc
from the terminal, if needed, and this should stop the problem.