Create one PHP FPM pool per shared folder

This commit is contained in:
Daniel Berteaud 2017-07-08 11:03:03 +02:00
parent 9c59939401
commit c6275f4299
2 changed files with 78 additions and 0 deletions

View File

@ -1,4 +1,6 @@
{
use esmith::AccountsDB;
my $a = esmith::AccountsDB->open_ro || die "Couldn't open the accounts database";
if ($fastcgi_mod eq 'mod_fastcgi'){
$OUT .=<<_EOF;
# mod_fastcgi global config
@ -29,7 +31,17 @@ Action php71-fastcgi /php-cgi-bin/php71-wrapper
Alias /php-cgi-bin/php71-wrapper /var/www/php-cgi-bin/php71-wrapper
FastCgiExternalServer /var/www/php-cgi-bin/php71-wrapper -socket /var/run/php-fpm/php71.sock -pass-header Authorization -idle-timeout 120
# Shared Folders
_EOF
foreach my $share ($a->get_all_by_prop(type => 'share')){
next if ($share->prop('DynamicContent' || 'disabled') ne 'enabled');
my $key = $share->key;
$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$key.sock -pass-header Authorization -idle-timeout 120
_EOF
}
}
else{
$OUT .= '# Using mod_proxy_fcgi, no additional config required'

View File

@ -0,0 +1,66 @@
{
use esmith::AccountsDB;
my $a = esmith::AccountsDB->open_ro || die "Couldn't open the accounts database";
foreach my $share ($a->get_all_by_prop(type => 'share')){
my $pool_name = $share->key;
next if (($share->prop('DynamicContent') || 'disabled') ne 'enabled');
my $memory_limit = $share->prop('PHPMemoryLimit') || '128M';
my $max_execution_time = $share->prop('PHPMaxExecutionTime') || '30';
my $allow_url_fopen = $share->prop('PHPAllowUrlFopen') || 'disabled';
my $post_max_size = $share->prop('PHPPostMaxSize') || '10M';
my $upload_max_filesize = $share->prop('PHPUploadMaxFilesize') || '10M';
my $file_upload = $share->prop('PHPFileUpload') || 'enabled';
my $open_basedir = $share->prop('PHPBaseDir') || '/home/e-smith/files/shares/' . $key . ':/var/lib/php/' . $pool_name;
my $disabled_functions = $share->prop('PHPDisabledFunctions') || 'system,show_source,' .
'symlink,exec,dl,shell_exec,' .
'passthru,phpinfo,' .
'escapeshellarg,escapeshellcmd';
# 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';
$disabled_functions = join(', ', split /[,;:]/, $disabled_functions);
my $version = $share->prop('PHPVersion') || 'default';
$OUT .=<<"_EOF" if ($version == $PHP_VERSION or ($PHP_VERSION eq '' && $version == 'default'));
[$pool_name]
user = www
group = www
listen.owner = root
listen.group = www
listen.mode = 0660
listen = /var/run/php-fpm/$pool_name.sock
pm = dynamic
pm.max_children = 15
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 4
pm.max_requests = 5000
request_terminate_timeout = 30
php_admin_value[session.save_path] = /var/lib/php/$pool_name/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/$pool_name/wsdlcache
php_value[opcache.file_cache] = /var/lib/php/$pool_name/opcache
php_admin_value[upload_tmp_dir] = /var/lib/php/$pool_name/tmp
php_admin_value[error_log] = /var/log/php/php/error.log
slowlog = /var/log/php/$pool_name/slow.log
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f php@{ $DomainName }
php_flag[display_errors] = off
php_admin_flag[log_errors] = on
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] = 60
php_admin_value[disable_functions] = $disabled_functions
php_admin_flag[allow_url_fopen] = $allow_url_fopen
php_admin_flag[file_upload] =
php_admin_flag[session.cookie_httponly] = on
php_admin_flag[allow_url_include] = off
php_value[session.save_handler] = files
_EOF
}
}