Add possibility to define custom PHP pools

This commit is contained in:
Daniel Berteaud 2017-07-14 12:23:57 +02:00
parent 10eb0f6551
commit daef899874
2 changed files with 96 additions and 0 deletions

View File

@ -1,6 +1,8 @@
{
use esmith::AccountsDB;
use esmith::ConfigDB;
my $a = esmith::AccountsDB->open_ro || die "Couldn't open the accounts database";
my $p = esmith::ConfigDB->open_ro('php') || esmith::ConfigDB->create('php');
if ($fastcgi_mod eq 'mod_fastcgi'){
$OUT .=<<_EOF;
# mod_fastcgi global config
@ -41,6 +43,18 @@ _EOF
Action php$key-fastcgi /php-cgi-bin/php$key-wrapper
Alias /php-cgi-bin/php$key-wrapper /var/www/php-cgi-bin/php$key-wrapper
FastCgiExternalServer /var/www/php-cgi-bin/php$key-wrapper -socket /var/run/php-fpm/php$ver-$key.sock -pass-header Authorization -idle-timeout 120
_EOF
# Custom PHP pools
foreach my $pool ($p->get_all_by_prop(type => 'pool')){
next if ($pool->prop('status' || 'enabled') ne 'enabled');
my $key = $pool->key;
my $ver = $pool->prop('Version') || '';
$OUT .=<<_EOF;
Action php$key-fastcgi /php-cgi-bin/php$key-wrapper
Alias /php-cgi-bin/php$key-wrapper /var/www/php-cgi-bin/php$key-wrapper
FastCgiExternalServer /var/www/php-cgi-bin/php$key-wrapper -socket /var/run/php-fpm/php$ver-$key.sock -pass-header Authorization -idle-timeout 120
_EOF
}
}

View File

@ -0,0 +1,82 @@
{
use esmith::ConfigDB;
my $pool_db = esmith::ConfigDB->open_ro('php') || esmith::ConfigDB->create('php');
foreach my $pool ($pool_db->get_all_by_prop(type => 'pool')){
my $version = $pool->prop('Version') || '';
my $status = $pool->prop('status') || 'enabled';
next unless ($version eq $PHP_VERSION && $status eq 'enabled');
my $key = $pool->key;
my $pool_name = 'php' . $version . '-' . $key;
my $memory_limit = $pool->prop('MemoryLimit') || '128M';
my $max_execution_time = $pool->prop('MaxExecutionTime') || '30';
my $max_input_time = $pool->prop('MaxInputTime') || '60';
my $allow_url_fopen = $pool->prop('AllowUrlFopen') || 'disabled';
my $post_max_size = $pool->prop('PostMaxSize') || '10M';
my $upload_max_filesize = $pool->prop('UploadMaxFilesize') || '10M';
my $file_upload = $pool->prop('FileUpload') || 'enabled';
my $open_basedir = $pool->prop('BaseDir') || undef;
my $disabled_functions = $pool->prop('DisabledFunctions') || 'system,show_source,' .
'symlink,exec,dl,shell_exec,' .
'passthru,phpinfo,' .
'escapeshellarg,escapeshellcmd';
my $user = $pool->prop('User') || 'www';
my $group = $pool->prop('Group') || $user;
my $max_children = $pool->prop('MaxChildren') || '15';
my $display_errors = $pool->prop('DisplayErrors') || 'disabled'
my $log_errors = $pool->prop('LogErrors') || 'disabled;
# Format vars
$file_upload = ($file_upload =~ m/^1|yes|on|enabled$/) ? 'on' : 'off';
$allow_url_fopen = ($allow_url_fopen =~ m/^1|yes|on|enabled$/) ? 'on' : 'off';
$display_errors = ($display_errors =~ m/^1|yes|on|enabled$/) ? 'on' : 'off';
$log_errors = ($log_errors =~ m/^1|yes|on|enabled$/) ? 'on' : 'off';
$disabled_functions = join(', ', split /[,;:]/, $disabled_functions);
$open_basedir = (defined $open_basedir) ? 'php_admin_value[open_basedir] = ' . join(':', split(/[,;:]/, $open_basedir)) :
'; open_basedir is not set';
$OUT .=<<"_EOF";
[$pool_name]
user = $user
group = $group
listen.owner = root
listen.group = www
listen.mode = 0660
listen = /var/run/php-fpm/$pool_name.sock
pm = dynamic
pm.max_children = $max_children
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 4
pm.max_requests = 1000
slowlog = /var/log/php/$key/slow.log
php_admin_value[session.save_path] = /var/lib/php/$key/session
php_admin_value[opcache.file_cache] = /var/lib/php/$key/opcache
php_admin_value[upload_tmp_dir] = /var/lib/php/$key/tmp
php_admin_value[error_log] = /var/log/php/$key/error.log
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f php@{ $DomainName }
php_admin_flag[display_errors] = $display_errors
php_admin_flag[log_errors] = $log_errors
php_admin_value[error_log] = syslog
php_admin_value[memory_limit] = $memory_limit
php_admin_value[max_execution_time] = $max_execution_time
php_admin_value[post_max_size] = $post_max_size
php_admin_value[upload_max_filesize] = $upload_max_filesize
php_admin_value[max_input_time] = $max_input_time
php_admin_value[disable_functions] = $disabled_functions
php_admin_flag[allow_url_fopen] = $allow_url_fopen
php_admin_flag[file_upload] = $file_upload
php_admin_flag[session.cookie_httponly] = on
php_admin_flag[allow_url_include] = off
php_admin_value[session.save_handler] = files
$open_basedir
_EOF
}
}