PHP warning : Module 'mcrypt' already loaded

后端 未结 4 1008
后悔当初
后悔当初 2021-02-12 17:57

When I run a command with PHP, it shows me an error. E.g when I run php -v to see my PHP-version it shows me an error then the informations about PHP:

4条回答
  •  生来不讨喜
    2021-02-12 18:43

    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.

提交回复
热议问题