PHP warning : Module 'mcrypt' already loaded

Sometimes this happens with php-fpm, and the funny thing is, console php doesn't complans about this using the same set of .ini-files in the same time, proving that mcrypt in fact isn't referenced twice.

As it turns out, php-fpm has a default set of modules built-in that it's trying to load, at least on Linux (since that isn't reproducible on FreeBSD). mcrypt is in this list, so when a user has an additional .ini-file in it's /etc/php.d directory, mcrypt seems to be loaded twice.

A harsh workaround for this is to add the -n switch to the php-fpm on the start, copy pnp.ini to a php-fpm.ini, include all of your modules into the resulting php-fpm.ini except mcrypt and add an additional switch pointing at the correct ini-file, so the whole addition looks like: -n -c /etc/php-fpm.ini.

This way running php-fpm won't complain.

I'm writing this here, because this is most referenced post in search engines about mcrypt issue. I realize the source question was about console php.

Update: I was using this workaround, but it is nasty. Some time ago I have figured out exactly why did this happen. I'll spend some more words to describe this, but this can be boring, since this will describe a certain type of failure. So, in my case this issue was caused by the fact, that I was using a custom php build, made by myself, and occasionally I've added the mcrypt to the list of builtin static modules. And then I added it again as a built module, so it was loaded twice. This happens with a custom build when mcrypt is referenced in the list of modules for the configure script, and isn't listed as shared (this part of the spec can be easily found, since %configure \ is mentioned only once in the spec). In my case the solution was to remove the mcrypt entirely from the configure part, and add it to the build-cgi and build-ztscli stages. One could ask " What about the fpm stage ?" - and it's a good question, but, it turns out, fpm sapi itself is built with a minimum of modules and uses generic shared ones.


Your php.ini contains two or more of these lines:

extension=mcrypt.so

Remove all except one.

php.ini usually lives in /etc/php.ini or /etc/php5/php.ini. Sometimes additional .ini files are included, you can see all of them with:

$ php -i | grep .ini\$
Loaded Configuration File => /usr/local/etc/php.ini
Additional .ini files parsed => /usr/local/etc/php/extensions.ini
user_ini.filename => .user.ini => .user.ini