B

bertin.louis7

September 29, 2025

Variables Custom et multi-env dans PHP-FPM avec un PaaS

Article Français
Le problĂšme
Adapter pm.max_spare, pm.start_servers sans dupliquer les configs.
Ici j'utilise Scalingo, mais c'est la mĂȘme idĂ©e pour d'autres PaaS

La solution
  1. - Template avec placeholders
    ; .scalingo/config/php-fpm/php-fpm-custom.conf
  2. pm.max_spare = PM_MAX_CHILDREN_PLACEHOLDER
    pm.start_servers = PM_START_SERVERS_PLACEHOLDER

  3. - Config Composer
  4. {
    "extra": {
    "paas": {
    "php-fpm-includes": [".scalingo/config/php-fpm/php-fpm-custom.conf"]
    }
    },
    "scripts": {
    "compile": ["php build.php"]
    }
    }

  1. - Script de remplacement
    1. ; build.php

  2. <?php
    
  3. $appName = getenv('APP') ?: 'default';
    $targetFile = '/app/vendor/php/etc/fpm.d/php-fpm-custom.conf';
    
  4. $phpFpmConfigs = [
        'default' => [
            'start_servers' => 3,
            'min_spare' => 3,
            'max_spare' => 7
        ]
    ];
    
    $config = $phpFpmConfigs[$appName] ?? $phpFpmConfigs['default'];
    
    shell_exec("sed -i 's|PM_START_SERVERS_PLACEHOLDER|{$config['start_servers']}|g' $targetFile");
    shell_exec("sed -i 's|PM_MIN_SPARE_PLACEHOLDER|{$config['min_spare']}|g' $targetFile");
    shell_exec("sed -i 's|PM_MAX_SPARE_PLACEHOLDER|{$config['max_spare']}|g' $targetFile");
B

bertin.louis7

Auteur de cet article