Does every PHP-FPM Worker individually download php.ini?

I installed PHP 5.3.8 from a source on Ubuntu Natty. I also enabled FPM during configuration.

However, I am having trouble installing PHP extensions. When I add the extension to the php.ini file (e.g. extension=apc.so ) and reload PHP (i.e. /etc/init.d/php-fpm restart ), I get an error message similar to the one below:

 Starting php-fpm PHP Warning: Module 'apc' already loaded in Unknown on line 0 <br /> <b>Warning</b>: Module 'apc' already loaded in <b>Unknown</b> on line <b>0</b><br /> PHP Warning: Module 'geoip' already loaded in Unknown on line 0 <br /> <b>Warning</b>: Module 'geoip' already loaded in <b>Unknown</b> on line <b>0</b><br /> PHP Warning: Module 'imagick' already loaded in Unknown on line 0 <br /> <b>Warning</b>: Module 'imagick' already loaded in <b>Unknown</b> on line <b>0</b><br /> PHP Warning: Module 'memcache' already loaded in Unknown on line 0 <br /> 

My PHP-FPM conf has the parameter pm.start_servers = 5 , so I have about 5 working PHP-FPMs. They all try to load the php.ini file when restarting PHP (hence the message that the module is already loaded) ?! If so, is there a way to prevent this from stopping the errors as errors become fatal when loading Zend Loader?

Thanks in advance.

+2
source share
3 answers

After a couple of hours, I managed to find a way to fix this. I suggest that this would be more useful for compiling and installing PHP with FPM from the source (all that you apt-get probably have nothing to do with this)

This is mainly due to using your php-fpm.conf to load all of your PHP extensions instead of php.ini. Here is what you do:

  • Open the php-fpm.conf file (I installed my php from the source, so I have mine on /usr/local/php/etc/php-fpm.conf based on how I install my --prefix and --with-config-file-path , but you can use find / -name "php-fpm.conf" from the bash shell to find where yours is).

  • Add your extension download directives (ideally at the end of the file). You have to be careful, as the format is a bit different. In your php.ini file it will look like extension=apc.so , but in your php-fpm.conf file it should be defined as follows: php_admin_value[extension]=apc.so

NOTE. Make sure your extension_dir file (where you saved all the .so files for your extensions) is defined in the php.ini file. Then restart php-fpm.

I have done this above and have no more errors, and all my extensions are displayed in phpinfo() .

Hope this helps someone, it almost drove me crazy.

Greetings.

EDIT

After further testing, I found that the problem was actually a bit more complicated. This is because PHP loads php.ini twice, because at compile time I specified the same place for --with-config-file-path and --with-config-file-scan-dir .

So, you would like to do the following as the best alternative to what I indicated above (which also works, but has a limitation, since you will not be able to download Zend extensions, for example IonCube Loader):

  • Compile PHP with the following option --with-config-file-scan-dir=/usr/local/php/etc/conf.d Make this another directory from --with-config-file-path .
  • Create a separate file to load the PHP extensions (you can call it phpext.ini) and save it in the location defined above ie /usr/local/php/etc/conf.d . In this file, define all the extensions you want to download, for example. extension=apc.so Your extensions should be stored in the /usr/lib/php5/20090626/ , which I assume should be the default directory. Make sure you do not define your extensions in the main php.ini file.
  • PHP reload

Now everything will work well, and you can download the Zend extensions (as they should be defined in your php.ini file and cannot be in php-fpm.conf).

Greetings.

+8
source

Ubuntu uses several confiugration files for PHP, often one for extension. If you install the extension using system software (for example, apt), you do not need to manually include the extension in the php.ini .

If you delete the files added in php.ini , this should solve your problem.

Optional: PHP reads all ini files once per active process.

0
source

Make sure that there is no geoip / apc sub-ini in / etc / php 5 / conf.d. Ubuntu tends to load external drivers by inserting their .ini into the conf.d directory and leaving the main .ini only.

0
source

Source: https://habr.com/ru/post/901845/


All Articles