Использование разных пулов PHP-FPM в Apache 2 с mod_fastcgi

Дано:
Есть сайт на Bitrix, установленный с поддержкой UTF-8 и все остальные сайты. Надо чтобы у сайта на Bitrix было php_admin_value mbstring.func_overload 2, а на остальных нет, т.к. остальные от этого ломаются. Также есть Apache2 с общим mod_fastcgi для всех хостов.
Конфиг для Bitrix сайта (как в прочем и для других) выглядит так:


        DocumentRoot /home/user/www/sitename
        ServerName sitename.com
        ErrorLog ${APACHE_LOG_DIR}/sitename.error.log
        ServerAdmin webmaster@sitename.com
        SetEnv ENV "development"

        
                AssignUserId user user
        

Конфиг mod_fastcgi:


        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php5-fcgi
        Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
        
                Require all granted
        

Вариант решения:
Создаем новый pool в PHP-FPM, переопределяем в нем php_admin_value[mbstring.func_overload] = 2 и указываем Apache’у использовать этот pool для виртаулхоста с Bitrix. При этом остальные будут использовать стандартный pool.

  1. Создаем новый PHP-FPM pool, меняем его имя, путь к сокету и дописываем в конец файла переопределения директив из `php.ini`:
    ; Start a new pool named 'www'.
    ; the variable $pool can we used in any directive and will be replaced by the
    ; pool name ('www' here)
    [bitrix-utf8]
    
    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
    ;                            a specific port;
    ;   'port'                 - to listen on a TCP socket to all addresses on a
    ;                            specific port;
    ;   '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.
    listen = /var/run/php5-fpm-bitrix-utf8.sock
    
    ; Additional php.ini defines, specific to this pool of workers. These settings
    ; overwrite the values previously defined in the php.ini. The directives are the
    ; same as the PHP SAPI:
    ;   php_value/php_flag             - you can set classic ini defines which can
    ;                                    be overwritten from PHP call 'ini_set'.
    ;   php_admin_value/php_admin_flag - these directives won't be overwritten by
    ;                                     PHP call 'ini_set'
    ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
    
    ; Defining 'extension' will load the corresponding shared extension from
    ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
    ; overwrite previously defined php.ini values, but will append the new value
    ; instead.
    
    ; Note: path INI options can be relative and will be expanded with the prefix
    ; (pool, global or /usr)
    
    ; Default Value: nothing is defined by default except the values in php.ini and
    ;                specified at startup with the -d argument
    ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
    ;php_flag[display_errors] = off
    ;php_admin_value[error_log] = /var/log/fpm-php.www.log
    ;php_admin_flag[log_errors] = on
    ;php_admin_value[memory_limit] = 32M
    
    php_admin_value[mbstring.func_overload] = 2
  2. Редактируем виртуалхост с Bitrix:
    
            DocumentRoot /home/user/www/sitename
            ServerName sitename.com
            ErrorLog ${APACHE_LOG_DIR}/sitename.error.log
            ServerAdmin webmaster@sitename.com
            SetEnv ENV "development"
    
            
                    AssignUserId user user
            
    
            
                    AddType application/x-httpd-fastphp5 .php
                    Action application/x-httpd-fastphp5 /php5-fcgi-bitrix-utf8
                    Alias /php5-fcgi-bitrix-utf8 /usr/lib/cgi-bin/php5-fcgi-bitrix-utf8
                    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi-bitrix-utf8 -socket /var/run/php5-fpm-bitrix-utf8.sock -pass-header Authorization
                    
                            Require all granted
                    
            
    

    Здесь мы добавили конфиг mod_fastcgi и немного изменили имя FCGI сервера и путь к сокету.

  3. Перезапускаем PHP-FPM и Apache:
    `sudo service php-fpm restart; sudo service apache2 reload`