diff --git a/actions/admin/settings/136.phpfpm.php b/actions/admin/settings/136.phpfpm.php new file mode 100644 index 00000000..4d18383b --- /dev/null +++ b/actions/admin/settings/136.phpfpm.php @@ -0,0 +1,122 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Settings + * @version $Id$ + */ + +return array( + 'groups' => array( + 'phpfpm' => array( + 'title' => $lng['admin']['phpfpm_settings'], + 'fields' => array( + 'system_phpfpm_enabled' => array( + 'label' => $lng['serversettings']['phpfpm'], + 'settinggroup' => 'phpfpm', + 'varname' => 'enabled', + 'type' => 'bool', + 'default' => false, + 'save_method' => 'storeSettingField', + 'overview_option' => true + ), + 'system_phpfpm_configdir' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['configdir'], + 'settinggroup' => 'phpfpm', + 'varname' => 'configdir', + 'type' => 'string', + 'string_type' => 'dir', + 'default' => '/etc/php-fpm.d/', + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_tmpdir' => array( + 'label' => $lng['serversettings']['mod_fcgid']['tmpdir'], + 'settinggroup' => 'phpfpm', + 'varname' => 'tmpdir', + 'type' => 'string', + 'string_type' => 'dir', + 'default' => '/var/customers/tmp/', + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_peardir' => array( + 'label' => $lng['serversettings']['mod_fcgid']['peardir'], + 'settinggroup' => 'phpfpm', + 'varname' => 'peardir', + 'type' => 'string', + 'string_type' => 'dir', + 'default' => '/usr/share/php/:/usr/share/php5/', + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_reload' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['reload'], + 'settinggroup' => 'phpfpm', + 'varname' => 'reload', + 'type' => 'string', + 'default' => '/etc/init.d/php-fpm restart', + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_pm' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['pm'], + 'settinggroup' => 'phpfpm', + 'varname' => 'pm', + 'type' => 'option', + 'default' => 'static', + 'option_mode' => 'one', + 'option_options' => array('static' => 'static', 'dynamic' => 'dynamic'), + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_max_children' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['max_children'], + 'settinggroup' => 'phpfpm', + 'varname' => 'max_children', + 'type' => 'int', + 'default' => 1, + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_start_servers' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['start_servers'], + 'settinggroup' => 'phpfpm', + 'varname' => 'start_servers', + 'type' => 'int', + 'default' => 20, + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_min_spare_servers' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['min_spare_servers'], + 'settinggroup' => 'phpfpm', + 'varname' => 'min_spare_servers', + 'type' => 'int', + 'default' => 5, + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_max_spare_servers' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['max_spare_servers'], + 'settinggroup' => 'phpfpm', + 'varname' => 'max_spare_servers', + 'type' => 'int', + 'default' => 35, + 'save_method' => 'storeSettingField', + ), + 'system_phpfpm_max_requests' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['max_requests'], + 'settinggroup' => 'phpfpm', + 'varname' => 'max_requests', + 'type' => 'int', + 'default' => 0, + 'save_method' => 'storeSettingField', + ), + ), + ), + ), + ); + +?> diff --git a/install/froxlor.sql b/install/froxlor.sql index 2ac219a8..87bea846 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -462,7 +462,7 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (18, 'system', 'vmail_homedir', '/var/customers/mail/'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (19, 'system', 'bindconf_directory', '/etc/bind/'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (20, 'system', 'bindreload_command', '/etc/init.d/bind9 reload'); -INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.15'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.16-svn1'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (23, 'system', 'hostname', 'SERVERNAME'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (24, 'login', 'maxloginattempts', '3'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (25, 'login', 'deactivatetime', '900'); @@ -597,6 +597,17 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (156, 'system', 'nginx_php_backend', '127.0.0.1:8888'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (157, 'system', 'perl_server', 'unix:/var/run/nginx/cgiwrap-dispatch.sock'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (158, 'system', 'phpreload_command', ''); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (159, 'phpfpm', 'enabled', '0'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (160, 'phpfpm', 'configdir', '/etc/php-fpm.d/'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (161, 'phpfpm', 'reload', '/etc/init.d/php-fpm restart'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (162, 'phpfpm', 'pm', 'static'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (163, 'phpfpm', 'max_children', '1'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (164, 'phpfpm', 'start_servers', '20'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (165, 'phpfpm', 'min_spare_servers', '5'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (166, 'phpfpm', 'max_spare_servers', '35'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (167, 'phpfpm', 'max_requests', '0'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (168, 'phpfpm', 'tmpdir', '/var/customers/tmp/'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (169, 'phpfpm', 'peardir', '/usr/share/php/:/usr/share/php5/'); # -------------------------------------------------------- diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 2bcc1d09..cc630008 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -1269,3 +1269,54 @@ if(isFroxlorVersion('0.9.15-svn1')) updateToVersion('0.9.15'); } + +if(isFroxlorVersion('0.9.15')) +{ + showUpdateStep("Updating from 0.9.15 to 0.9.16-svn1", false); + + $update_phpfpm_enabled = isset($_POST['update_phpfpm_enabled']) ? (int)$_POST['update_phpfpm_enabled'] : '0'; + $update_phpfpm_configdir = isset($_POST['update_phpfpm_configdir']) ? makeCorrectDir($_POST['update_phpfpm_configdir']) : '/etc/php-fpm.d/'; + $update_phpfpm_tmpdir = isset($_POST['update_phpfpm_tmpdir']) ? makeCorrectDir($_POST['update_phpfpm_tmpdir']) : '/var/customers/tmp'; + $update_phpfpm_peardir = isset($_POST['update_phpfpm_peardir']) ? makeCorrectDir($_POST['update_phpfpm_peardir']) : '/usr/share/php/:/usr/share/php5/'; + $update_phpfpm_reload = isset($_POST['update_phpfpm_reload']) ? $_POST['update_phpfpm_reload'] : '/etc/init.d/php-fpm restart'; + + $update_phpfpm_pm = isset($_POST['update_phpfpm_pm']) ? $_POST['update_phpfpm_pm'] : 'static'; + $update_phpfpm_max_children = isset($_POST['update_phpfpm_max_children']) ? (int)$_POST['update_phpfpm_max_children'] : '1'; + $update_phpfpm_max_requests = isset($_POST['update_phpfpm_max_requests']) ? (int)$_POST['update_phpfpm_max_requests'] : '0'; + + if($update_phpfpm_pm == 'dynamic') + { + $update_phpfpm_start_servers = isset($_POST['update_phpfpm_start_servers']) ? (int)$_POST['update_phpfpm_start_servers'] : '20'; + $update_phpfpm_min_spare_servers = isset($_POST['update_phpfpm_min_spare_servers']) ? (int)$_POST['update_phpfpm_min_spare_servers'] : '5'; + $update_phpfpm_max_spare_servers = isset($_POST['update_phpfpm_max_spare_servers']) ? (int)$_POST['update_phpfpm_max_spare_servers'] : '35'; + } + else + { + $update_phpfpm_start_servers = 20; + $update_phpfpm_min_spare_servers = 5; + $update_phpfpm_max_spare_servers = 35; + } + + if($update_phpfpm_configdir == '') { + $update_phpfpm_configdir = '/etc/php-fpm.d/'; + } + if($update_phpfpm_reload == '') { + $update_phpfpm_reload = '/etc/init.d/php-fpm restart'; + } + + showUpdateStep("Adding new settings"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'enabled', '".(int)$update_phpfpm_enabled."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'configdir', '".$db->escape($update_phpfpm_configdir)."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'reload', '".$db->escape($update_phpfpm_reload)."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'pm', '".$db->escape($update_phpfpm_pm)."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'max_children', '".(int)$update_phpfpm_max_children."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'max_requests', '".(int)$update_phpfpm_max_requests."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'start_servers', '".(int)$update_phpfpm_start_servers."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'min_spare_servers', '".(int)$update_phpfpm_min_spare_servers."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'max_spare_servers', '".(int)$update_phpfpm_max_spare_servers."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'tmpdir', '".$db->escape($update_phpfpm_tmpdir)."');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('phpfpm', 'peardir', '".$db->escape($update_phpfpm_peardir)."');"); + lastStepStatus(0); + + updateToVersion('0.9.16-svn1'); +} diff --git a/install/updates/preconfig/0.9/preconfig_0.9.inc.php b/install/updates/preconfig/0.9/preconfig_0.9.inc.php index ff7c751c..6ce1bdfb 100644 --- a/install/updates/preconfig/0.9/preconfig_0.9.inc.php +++ b/install/updates/preconfig/0.9/preconfig_0.9.inc.php @@ -351,4 +351,37 @@ function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version) $question = ''; eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); } + + if(versionInUpdate($current_version, '0.9.16-svn1')) + { + $has_preconfig = true; + $description = 'Froxlor now features support for php-fpm.'; + $question = 'Do you want to enable php-fpm?: '; + $question.= makeyesno('update_phpfpm_enabled', '1', '0', '0').'

'; + $question.= 'If \'yes\', please specify the configuration directory: '; + $question.= '

'; + $question.= 'Please specify the temporary files directory: '; + $question.= '

'; + $question.= 'Please specify the PEAR directory: '; + $question.= '

'; + $question.= 'Please specify the php-fpm restart-command: '; + $question.= '

'; + $question.= 'Please specify the php-fpm rocess manager control: '; + $question.= '

'; + $question.= 'Please specify the number of child processes: '; + $question.= '

'; + $question.= 'Please specify the number of requests per child before respawning: '; + $question.= '

'; + $question.= 'The following settings are only required if you chose process manager = dynamic

'; + $question.= 'Please specify the number of child processes created on startup: '; + $question.= '

'; + $question.= 'Please specify the desired minimum number of idle server processes: '; + $question.= '

'; + $question.= 'Please specify the desired maximum number of idle server processes: '; + $question.= '
'; + eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); + } } diff --git a/lib/tables.inc.php b/lib/tables.inc.php index 257f96c6..c348ad6a 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -71,7 +71,7 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.15'; +$version = '0.9.16-svn1'; $dbversion = '2'; $branding = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index 724a0361..860139d3 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1526,3 +1526,18 @@ $lng['serversettings']['phpreload_command']['description'] = 'this is used to re // ADDED IN FROXLOR 0.9.16 $lng['error']['intvaluetoolow'] = 'The given number is too low (field %s)'; $lng['error']['intvaluetoohigh'] = 'The given number is too high (field %s)'; +$lng['admin']['phpfpm_settings'] = 'PHP-FPM'; +$lng['serversettings']['phpfpm'] = 'Enable php-fpm'; +$lng['serversettings']['phpfpm_settings']['configdir'] = 'Configuration directory of php-fpm'; +$lng['serversettings']['phpfpm_settings']['reload'] = 'php-fpm restart command'; +$lng['serversettings']['phpfpm_settings']['pm'] = 'Process manager control (pm)'; +$lng['serversettings']['phpfpm_settings']['max_children']['title'] = 'The number of child processes'; +$lng['serversettings']['phpfpm_settings']['max_children']['description'] = 'The number of child processes to be created when pm is set to \'static\' and the maximum number of child processes to be created when pm is set to \'dynamic\'
Equivalent to the PHP_FCGI_CHILDREN'; +$lng['serversettings']['phpfpm_settings']['start_servers']['title'] = 'The number of child processes created on startup'; +$lng['serversettings']['phpfpm_settings']['start_servers']['description'] = 'Note: Used only when pm is set to \'dynamic\''; +$lng['serversettings']['phpfpm_settings']['min_spare_servers']['title'] = 'The desired minimum number of idle server processes'; +$lng['serversettings']['phpfpm_settings']['min_spare_servers']['description'] = 'Note: Used only when pm is set to \'dynamic\'
Note: Mandatory when pm is set to \'dynamic\''; +$lng['serversettings']['phpfpm_settings']['max_spare_servers']['title'] = 'The desired maximum number of idle server processes'; +$lng['serversettings']['phpfpm_settings']['max_spare_servers']['description'] = 'Note: Used only when pm is set to \'dynamic\'
Note: Mandatory when pm is set to \'dynamic\''; +$lng['serversettings']['phpfpm_settings']['max_requests']['title'] = 'Requests per child before respawning'; +$lng['serversettings']['phpfpm_settings']['max_requests']['description'] = 'For endless request processing specify \'0\'. Equivalent to PHP_FCGI_MAX_REQUESTS.'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 3d74eef4..68234869 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1508,3 +1508,18 @@ $lng['serversettings']['phpreload_command']['description'] = 'Dieser wird ben&ou // ADDED IN FROXLOR 0.9.16 $lng['error']['intvaluetoolow'] = 'Die angegebene Zahl ist zu klein (Feld %s)'; $lng['error']['intvaluetoohigh'] = 'Die angegebene Zahl ist zu groß (Feld %s)'; +$lng['admin']['phpfpm_settings'] = 'PHP-FPM'; +$lng['serversettings']['phpfpm'] = 'Aktiviere php-fpm'; +$lng['serversettings']['phpfpm_settings']['configdir'] = 'Pfad zu php-fpm Konfigurationen'; +$lng['serversettings']['phpfpm_settings']['reload'] = 'Kommando zum Neustarten von php-fpm'; +$lng['serversettings']['phpfpm_settings']['pm'] = 'Prozess Manager Control (PM)'; +$lng['serversettings']['phpfpm_settings']['max_children']['title'] = 'Anzahl der Kind-Prozesse'; +$lng['serversettings']['phpfpm_settings']['max_children']['description'] = 'Die Anzahl der zu startenden Kind-Prozesse wenn PM auf \'static\' steht und die maximale Anzahl der Prozesse wenn PM auf \'dynamic\' steht.
Equivalent zu PHP_FCGI_CHILDREN'; +$lng['serversettings']['phpfpm_settings']['start_servers']['title'] = 'Anzahl der beim Starten zu erstellenden Kind-Prozesse'; +$lng['serversettings']['phpfpm_settings']['start_servers']['description'] = 'Hinweis: Nur wenn PM auf \'dynamic\' steht'; +$lng['serversettings']['phpfpm_settings']['min_spare_servers']['title'] = 'Mindestanzahl der Idle-Prozesse'; +$lng['serversettings']['phpfpm_settings']['min_spare_servers']['description'] = 'Hinweis: Nur wenn PM auf \'dynamic\' steht
Wichtig: Pflichtangabe wenn PM auf \'dynamic\' steht'; +$lng['serversettings']['phpfpm_settings']['max_spare_servers']['title'] = 'Maximale Anzahl der Idle-Prozesse'; +$lng['serversettings']['phpfpm_settings']['max_spare_servers']['description'] = 'Hinweis: Nur wenn PM auf \'dynamic\' steht
Wichtig: Pflichtangabe wenn PM auf \'dynamic\' steht'; +$lng['serversettings']['phpfpm_settings']['max_requests']['title'] = 'Requests pro Kindprozess bevor Neuerstellung (respawning)'; +$lng['serversettings']['phpfpm_settings']['max_requests']['description'] = 'Für keine Begrenzung \'0\' angeben. Equivalent zu PHP_FCGI_MAX_REQUESTS.'; diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index a747b311..8d6fed13 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -57,6 +57,12 @@ class apache public function reload() { + if((int)$this->settings['phpfpm']['enabled'] == 1) + { + fwrite($this->debugHandler, ' apache::reload: reloading php-fpm' . "\n"); + $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading php-fpm'); + safe_exec(escapeshellcmd($this->settings['phpfpm']['reload'])); + } fwrite($this->debugHandler, ' apache::reload: reloading apache' . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading apache'); safe_exec(escapeshellcmd($this->settings['system']['apachereload_command'])); @@ -76,9 +82,10 @@ class apache } $vhosts_filename = makeCorrectFile($vhosts_folder . '/05_froxlor_dirfix_nofcgid.conf'); - if($this->settings['system']['mod_fcgid'] == '1') - { - // if we use fcgid we don't need this file + if($this->settings['system']['mod_fcgid'] == '1' + || $this->settings['phpfpm']['enabled'] == '1' + ) { + // if we use fcgid or php-fpm we don't need this file if(file_exists($vhosts_filename)) { fwrite($this->debugHandler, ' apache::_createStandardDirectoryEntry: unlinking ' . basename($vhosts_filename) . "\n"); diff --git a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php index 4d90e848..cd692e7b 100644 --- a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php +++ b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php @@ -39,206 +39,213 @@ class apache_fcgid extends apache if($domain['phpenabled'] == '1') { - // This vHost has PHP enabled and we are using mod_fcgid - //create basic variables for config - - $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/'); - $starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter'); - $phpini_filename = makeCorrectFile($configdir . '/php.ini'); - $tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/'); - - // create config dir if necessary - - if(!is_dir($configdir)) + if((int)$this->settings['phpfpm']['enabled'] == 1) { - safe_exec('mkdir -p ' . escapeshellarg($configdir)); - safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir)); - } - - // create tmp dir if necessary - - if(!is_dir($tmpdir)) - { - safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); - safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir)); - safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); - } - - // Load php config - - $phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']); - - if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) - { - $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; - $php_options_text.= ' ScriptAlias /php/ ' . $configdir . "\n"; + $php_options_text = $this->_createFpmPart($domain); } else { - $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; - $php_options_text.= ' ' . "\n"; - $file_extensions = explode(' ', $phpconfig['file_extensions']); - $php_options_text.= ' AddHandler fcgid-script .' . implode(' .', $file_extensions) . "\n"; - foreach($file_extensions as $file_extension) + // This vHost has PHP enabled and we are using mod_fcgid + //create basic variables for config + + $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/'); + $starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter'); + $phpini_filename = makeCorrectFile($configdir . '/php.ini'); + $tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/'); + + // create config dir if necessary + + if(!is_dir($configdir)) { - $php_options_text.= ' FCGIWrapper ' . $starter_filename . ' .' . $file_extension . "\n"; + safe_exec('mkdir -p ' . escapeshellarg($configdir)); + safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir)); } - - $php_options_text.= ' Options +ExecCGI' . "\n"; - $php_options_text.= ' Order allow,deny' . "\n"; - $php_options_text.= ' allow from all' . "\n"; - $php_options_text.= ' ' . "\n"; - } - - // create starter - - $starter_file = "#!/bin/sh\n\n"; - $starter_file.= "#\n"; - $starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; - $starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; - $starter_file.= "#\n\n"; - $starter_file.= "umask 022\n"; - $starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n"; - $starter_file.= "export PHPRC\n"; - - // set number of processes for one domain - - if((int)$domain['mod_fcgid_starter'] != - 1) - { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_starter'] != - 1) + + // create tmp dir if necessary + + if(!is_dir($tmpdir)) { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n"; + safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); + safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir)); + safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); + } + + // Load php config + + $phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']); + + if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) + { + $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; + $php_options_text.= ' ScriptAlias /php/ ' . $configdir . "\n"; } else { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n"; - } - } - - $starter_file.= "export PHP_FCGI_CHILDREN\n"; - - // set number of maximum requests for one domain - - if((int)$domain['mod_fcgid_maxrequests'] != - 1) - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n"; - } - else - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n"; - } - } - - $starter_file.= "export PHP_FCGI_MAX_REQUESTS\n"; - - // Set Binary - - $starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n"; - - //remove +i attibute, so starter can be overwritten - - if(file_exists($starter_filename)) - { - removeImmutable($starter_filename); - } - - $starter_file_handler = fopen($starter_filename, 'w'); - fwrite($starter_file_handler, $starter_file); - fclose($starter_file_handler); - safe_exec('chmod 750 ' . escapeshellarg($starter_filename)); - safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename)); - setImmutable($starter_filename); - - // define the php.ini - - $openbasedir = ''; - $openbasedirc = ';'; - - if($domain['openbasedir'] == '1') - { - $openbasedirc = ''; - $_phpappendopenbasedir = ''; - - $_custom_openbasedir = explode(':', $this->settings['system']['mod_fcgid_peardir']); - foreach($_custom_openbasedir as $cobd) - { - $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); - } - - $_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']); - foreach($_custom_openbasedir as $cobd) - { - $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); - } - - if($domain['openbasedir_path'] == '0' && strstr($domain['documentroot'], ":") === false) - { - $openbasedir = appendOpenBasedirPath($domain['documentroot'], true); - } - else - { - $openbasedir = appendOpenBasedirPath($domain['customerroot'], true); - } - - $openbasedir .= appendOpenBasedirPath($tmpdir); - $openbasedir .= $_phpappendopenbasedir; - - $openbasedir = explode(':', $openbasedir); - $clean_openbasedir = array(); - foreach($openbasedir as $number => $path) - { - if(trim($path) != '/') + $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; + $php_options_text.= ' ' . "\n"; + $file_extensions = explode(' ', $phpconfig['file_extensions']); + $php_options_text.= ' AddHandler fcgid-script .' . implode(' .', $file_extensions) . "\n"; + foreach($file_extensions as $file_extension) { - $clean_openbasedir[] = makeCorrectDir($path); + $php_options_text.= ' FCGIWrapper ' . $starter_filename . ' .' . $file_extension . "\n"; + } + + $php_options_text.= ' Options +ExecCGI' . "\n"; + $php_options_text.= ' Order allow,deny' . "\n"; + $php_options_text.= ' allow from all' . "\n"; + $php_options_text.= ' ' . "\n"; + } + + // create starter + + $starter_file = "#!/bin/sh\n\n"; + $starter_file.= "#\n"; + $starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; + $starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; + $starter_file.= "#\n\n"; + $starter_file.= "umask 022\n"; + $starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n"; + $starter_file.= "export PHPRC\n"; + + // set number of processes for one domain + + if((int)$domain['mod_fcgid_starter'] != - 1) + { + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n"; + } + else + { + if((int)$phpconfig['mod_fcgid_starter'] != - 1) + { + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n"; + } + else + { + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n"; } } - $openbasedir = implode(':', $clean_openbasedir); - } - else - { - $openbasedir = 'none'; + + $starter_file.= "export PHP_FCGI_CHILDREN\n"; + + // set number of maximum requests for one domain + + if((int)$domain['mod_fcgid_maxrequests'] != - 1) + { + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n"; + } + else + { + if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) + { + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n"; + } + else + { + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n"; + } + } + + $starter_file.= "export PHP_FCGI_MAX_REQUESTS\n"; + + // Set Binary + + $starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n"; + + //remove +i attibute, so starter can be overwritten + + if(file_exists($starter_filename)) + { + removeImmutable($starter_filename); + } + + $starter_file_handler = fopen($starter_filename, 'w'); + fwrite($starter_file_handler, $starter_file); + fclose($starter_file_handler); + safe_exec('chmod 750 ' . escapeshellarg($starter_filename)); + safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename)); + setImmutable($starter_filename); + + // define the php.ini + + $openbasedir = ''; $openbasedirc = ';'; + + if($domain['openbasedir'] == '1') + { + $openbasedirc = ''; + $_phpappendopenbasedir = ''; + + $_custom_openbasedir = explode(':', $this->settings['system']['mod_fcgid_peardir']); + foreach($_custom_openbasedir as $cobd) + { + $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); + } + + $_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']); + foreach($_custom_openbasedir as $cobd) + { + $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); + } + + if($domain['openbasedir_path'] == '0' && strstr($domain['documentroot'], ":") === false) + { + $openbasedir = appendOpenBasedirPath($domain['documentroot'], true); + } + else + { + $openbasedir = appendOpenBasedirPath($domain['customerroot'], true); + } + + $openbasedir .= appendOpenBasedirPath($tmpdir); + $openbasedir .= $_phpappendopenbasedir; + + $openbasedir = explode(':', $openbasedir); + $clean_openbasedir = array(); + foreach($openbasedir as $number => $path) + { + if(trim($path) != '/') + { + $clean_openbasedir[] = makeCorrectDir($path); + } + } + $openbasedir = implode(':', $clean_openbasedir); + } + else + { + $openbasedir = 'none'; + $openbasedirc = ';'; + } + + $admin = $this->getAdminData($domain['adminid']); + $php_ini_variables = array( + 'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'), + 'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'], + 'OPEN_BASEDIR' => $openbasedir, + 'OPEN_BASEDIR_C' => $openbasedirc, + 'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'], + 'TMP_DIR' => $tmpdir, + 'CUSTOMER_EMAIL' => $domain['email'], + 'ADMIN_EMAIL' => $admin['email'], + 'DOMAIN' => $domain['domain'], + 'CUSTOMER' => $domain['loginname'], + 'ADMIN' => $admin['loginname'] + ); + + //insert a small header for the file + + $phpini_file = ";\n"; + $phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; + $phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; + $phpini_file.= ";\n\n"; + $phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables); + $phpini_file = str_replace('"none"', 'none', $phpini_file); + $phpini_file = preg_replace('/\"+/', '"', $phpini_file); + $phpini_file_handler = fopen($phpini_filename, 'w'); + fwrite($phpini_file_handler, $phpini_file); + fclose($phpini_file_handler); + safe_exec('chown root:0 ' . escapeshellarg($phpini_filename)); + safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename)); } - - $admin = $this->getAdminData($domain['adminid']); - $php_ini_variables = array( - 'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'), - 'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'], - 'OPEN_BASEDIR' => $openbasedir, - 'OPEN_BASEDIR_C' => $openbasedirc, - 'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'], - 'TMP_DIR' => $tmpdir, - 'CUSTOMER_EMAIL' => $domain['email'], - 'ADMIN_EMAIL' => $admin['email'], - 'DOMAIN' => $domain['domain'], - 'CUSTOMER' => $domain['loginname'], - 'ADMIN' => $admin['loginname'] - ); - - //insert a small header for the file - - $phpini_file = ";\n"; - $phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; - $phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; - $phpini_file.= ";\n\n"; - $phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables); - $phpini_file = str_replace('"none"', 'none', $phpini_file); - $phpini_file = preg_replace('/\"+/', '"', $phpini_file); - $phpini_file_handler = fopen($phpini_filename, 'w'); - fwrite($phpini_file_handler, $phpini_file); - fclose($phpini_file_handler); - safe_exec('chown root:0 ' . escapeshellarg($phpini_filename)); - safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename)); } else { @@ -391,6 +398,82 @@ class apache_fcgid extends apache } } -} + private function _createFpmPart($domain) + { + $php_options_text = ''; -?> + if(!is_dir('/var/run/apache2/')) { + safe_exec('mkdir -p /var/run/apache2/'); + safe_exec('chown -R '.$this->settings['system']['httpuser'].':'.$this->settings['system']['httpgroup'].' /var/run/apache2/'); + } + $socket = makeCorrectFile('/var/run/apache2/'.$domain['loginname'].'-'.$domain['domain'].'-php-fpm.socket'); + $tmpfile = makeCorrectFile($this->settings['phpfpm']['configdir'].'/'.$domain['domain'].'.conf'); + + $fh = @fopen($tmpfile, 'w'); + if($fh) + { + $fpm_pm = $this->settings['phpfpm']['pm']; + $fpm_children = (int)$this->settings['phpfpm']['max_children']; + $fpm_start_servers = (int)$this->settings['phpfpm']['start_servers']; + $fpm_min_spare_servers = (int)$this->settings['phpfpm']['min_spare_servers']; + $fpm_max_spare_servers = (int)$this->settings['phpfpm']['max_spare_servers']; + $fpm_requests = (int)$this->settings['phpfpm']['max_requests']; + + if($fpm_children == 0) { + $fpm_children = 1; + } + + $tmpdir = makeCorrectDir($this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/'); + //$slowlog = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . '/php-fpm_slow.log'); + + $fpm_config = ';PHP-FPM configuration for "'.$domain['domain'].'" created on ' . date("Y.m.d H:i:s") . "\n\n"; + $fpm_config.= '['.$domain['domain'].']'."\n"; + $fpm_config.= 'listen = '.$socket."\n"; + $fpm_config.= 'listen.owner = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.group = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.mode = 0666'."\n\n"; + + $fpm_config.= 'user = '.$domain['loginname']."\n"; + $fpm_config.= 'group = '.$domain['loginname']."\n\n"; + + $fpm_config.= 'pm = '.$fpm_pm."\n"; + $fpm_config.= 'pm.max_children = '.$fpm_children."\n"; + if($fpm_pm == 'dynamic') { + $fpm_config.= 'pm.start_servers = '.$fpm_start_servers."\n"; + $fpm_config.= 'pm.min_spare_servers = '.$fpm_min_spare_servers."\n"; + $fpm_config.= 'pm.max_spare_servers = '.$fpm_max_spare_servers."\n"; + } + $fpm_config.= 'pm.max_requests = '.$fpm_requests."\n\n"; + + $fpm_config.= ';chroot = '.makeCorrectDir($domain['documentroot'])."\n\n"; + + $fpm_config.= 'env[TMP] = '.$tmpdir."\n"; + $fpm_config.= 'env[TMPDIR] = '.$tmpdir."\n"; + $fpm_config.= 'env[TEMP] = '.$tmpdir."\n\n"; + + $fpm_config.= 'php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f '.$domain['email']."\n\n"; + $fpm_config.= 'php_admin_value[open_basedir] = ' . $this->settings['system']['documentroot_prefix'] . $domain['loginname'] . '/:' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/:' . $this->settings['phpfpm']['peardir'] . "\n"; + $fpm_config.= 'php_admin_value[session.save_path] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n"; + $fpm_config.= 'php_admin_value[upload_tmp_dir] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n\n"; + + fwrite($fh, $fpm_config, strlen($fpm_config)); + fclose($fh); + + $php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n"; + $php_options_text.= ' FastCgiExternalServer ' . makeCorrectDir($domain['documentroot']) . 'fpm.external -socket ' . $socket . ' -user ' . $domain['loginname'] . ' -group ' . $domain['loginname'] . "\n"; + $php_options_text.= ' ' . "\n"; + $php_options_text.= ' AddHandler php5-fastcgi .php'. "\n"; + $php_options_text.= ' Action php5-fastcgi /fastcgiphp' . "\n"; + $php_options_text.= ' Options +ExecCGI' . "\n"; + $php_options_text.= ' Order allow,deny' . "\n"; + $php_options_text.= ' allow from all' . "\n"; + $php_options_text.= ' ' . "\n"; + $php_options_text.= ' Alias /fastcgiphp ' . makeCorrectDir($domain['documentroot']) . 'fpm.external' . "\n"; + } + else + { + $php_options_text = ' # could not create php-fpm configuration for '.$domain['domain']. "\n"; + } + return $php_options_text; + } +} diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index 22664ce6..f6e78457 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -61,6 +61,12 @@ class lighttpd public function reload() { + if((int)$this->settings['phpfpm']['enabled'] == 1) + { + fwrite($this->debugHandler, ' lighttpd::reload: reloading php-fpm' . "\n"); + $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading php-fpm'); + safe_exec(escapeshellcmd($this->settings['phpfpm']['reload'])); + } fwrite($this->debugHandler, ' lighttpd::reload: reloading lighttpd' . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading lighttpd'); safe_exec(escapeshellcmd($this->settings['system']['apachereload_command'])); diff --git a/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php b/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php index 0f267515..63a1daab 100644 --- a/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php +++ b/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php @@ -37,232 +37,239 @@ class lighttpd_fcgid extends lighttpd if($domain['phpenabled'] == '1') { - // This vHost has PHP enabled and we are using mod_fcgid - //create basic variables for config - - $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/'); - $starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter'); - $phpini_filename = makeCorrectFile($configdir . '/php.ini'); - $tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/'); - - // create config dir if necessary - - if(!is_dir($configdir)) + if((int)$this->settings['phpfpm']['enabled'] == 1) { - safe_exec('mkdir -p ' . escapeshellarg($configdir)); - safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir)); + $php_options_text = $this->_createFpmPart($domain); } - - // create tmp dir if necessary - - if(!is_dir($tmpdir)) + else { - safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); - safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir)); - safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); - } - - // Load php config - - $phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']); - - $php_options_text = ' fastcgi.server = ( '."\n"; - $file_extensions = explode(' ', $phpconfig['file_extensions']); - foreach($file_extensions as $f_extension) - { - $php_options_text.= "\t".'".'.$f_extension.'" => ('."\n"; - $php_options_text.= "\t\t".'"localhost" => ('."\n"; - $php_options_text.= "\t\t".'"socket" => "/var/run/lighttpd/'.$domain['loginname'].'-'.$domain['domain'].'-php.socket",'."\n"; - $php_options_text.= "\t\t".'"bin-path" => "'.$phpconfig['binary'].' -c '.$phpini_filename.'",'."\n"; - $php_options_text.= "\t\t".'"bin-environment" => ('."\n"; + // This vHost has PHP enabled and we are using mod_fcgid + //create basic variables for config + + $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/'); + $starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter'); + $phpini_filename = makeCorrectFile($configdir . '/php.ini'); + $tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/'); + + // create config dir if necessary + + if(!is_dir($configdir)) + { + safe_exec('mkdir -p ' . escapeshellarg($configdir)); + safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir)); + } + + // create tmp dir if necessary + + if(!is_dir($tmpdir)) + { + safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); + safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir)); + safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); + } + + // Load php config + + $phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']); + + $php_options_text = ' fastcgi.server = ( '."\n"; + $file_extensions = explode(' ', $phpconfig['file_extensions']); + foreach($file_extensions as $f_extension) + { + $php_options_text.= "\t".'".'.$f_extension.'" => ('."\n"; + $php_options_text.= "\t\t".'"localhost" => ('."\n"; + $php_options_text.= "\t\t".'"socket" => "/var/run/lighttpd/'.$domain['loginname'].'-'.$domain['domain'].'-php.socket",'."\n"; + $php_options_text.= "\t\t".'"bin-path" => "'.$phpconfig['binary'].' -c '.$phpini_filename.'",'."\n"; + $php_options_text.= "\t\t".'"bin-environment" => ('."\n"; + if((int)$domain['mod_fcgid_starter'] != - 1) + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$domain['mod_fcgid_starter'] . '",'."\n"; + } + else + { + if((int)$phpconfig['mod_fcgid_starter'] != - 1) + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$phpconfig['mod_fcgid_starter'] . '",'."\n"; + } + else + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$this->settings['system']['mod_fcgid_starter'] . '",'."\n"; + } + } + + if((int)$domain['mod_fcgid_maxrequests'] != - 1) + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$domain['mod_fcgid_maxrequests'] . '"'."\n"; + } + else + { + if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$phpconfig['mod_fcgid_maxrequests'] . '"'."\n"; + } + else + { + $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$this->settings['system']['mod_fcgid_maxrequests'] . '"'."\n"; + } + } + + $php_options_text.= "\t\t".')'."\n"; + $php_options_text.= "\t".')'."\n"; + $php_options_text.= "\t".')'."\n"; + + } // foreach extension + $php_options_text.= ' )'."\n"; + + // create starter + + $starter_file = "#!/bin/sh\n\n"; + $starter_file.= "#\n"; + $starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; + $starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; + $starter_file.= "#\n\n"; + $starter_file.= "umask 022\n"; + $starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n"; + $starter_file.= "export PHPRC\n"; + + // set number of processes for one domain + if((int)$domain['mod_fcgid_starter'] != - 1) { - $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$domain['mod_fcgid_starter'] . '",'."\n"; + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n"; } else { if((int)$phpconfig['mod_fcgid_starter'] != - 1) { - $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$phpconfig['mod_fcgid_starter'] . '",'."\n"; + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n"; } else { - $php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$this->settings['system']['mod_fcgid_starter'] . '",'."\n"; + $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n"; } } - + + $starter_file.= "export PHP_FCGI_CHILDREN\n"; + + // set number of maximum requests for one domain + if((int)$domain['mod_fcgid_maxrequests'] != - 1) { - $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$domain['mod_fcgid_maxrequests'] . '"'."\n"; + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n"; } else { if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) { - $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$phpconfig['mod_fcgid_maxrequests'] . '"'."\n"; + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n"; } else { - $php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$this->settings['system']['mod_fcgid_maxrequests'] . '"'."\n"; + $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n"; } } - - $php_options_text.= "\t\t".')'."\n"; - $php_options_text.= "\t".')'."\n"; - $php_options_text.= "\t".')'."\n"; - - } // foreach extension - $php_options_text.= ' )'."\n"; - - // create starter - - $starter_file = "#!/bin/sh\n\n"; - $starter_file.= "#\n"; - $starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; - $starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; - $starter_file.= "#\n\n"; - $starter_file.= "umask 022\n"; - $starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n"; - $starter_file.= "export PHPRC\n"; - - // set number of processes for one domain - - if((int)$domain['mod_fcgid_starter'] != - 1) - { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_starter'] != - 1) + + $starter_file.= "export PHP_FCGI_MAX_REQUESTS\n"; + + // Set Binary + + $starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n"; + + //remove +i attibute, so starter can be overwritten + + if(file_exists($starter_filename)) { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n"; + removeImmutable($starter_filename); } - else - { - $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n"; - } - } - - $starter_file.= "export PHP_FCGI_CHILDREN\n"; - - // set number of maximum requests for one domain - - if((int)$domain['mod_fcgid_maxrequests'] != - 1) - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n"; - } - else - { - $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n"; - } - } - - $starter_file.= "export PHP_FCGI_MAX_REQUESTS\n"; - - // Set Binary - - $starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n"; - - //remove +i attibute, so starter can be overwritten - - if(file_exists($starter_filename)) - { - removeImmutable($starter_filename); - } - - $starter_file_handler = fopen($starter_filename, 'w'); - fwrite($starter_file_handler, $starter_file); - fclose($starter_file_handler); - safe_exec('chmod 750 ' . escapeshellarg($starter_filename)); - safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename)); - setImmutable($starter_filename); - - // define the php.ini - - $openbasedir = ''; - $openbasedirc = ';'; - - if($domain['openbasedir'] == '1') - { - $openbasedirc = ''; - $_phpappendopenbasedir = ''; - - $_custom_openbasedir = explode(':', $this->settings['system']['mod_fcgid_peardir']); - foreach($_custom_openbasedir as $cobd) - { - $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); - } - - $_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']); - foreach($_custom_openbasedir as $cobd) - { - $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); - } - - if($domain['openbasedir_path'] == '0' && strstr($domain['documentroot'], ":") === false) - { - $openbasedir = appendOpenBasedirPath($domain['documentroot'], true); - } - else - { - $openbasedir = appendOpenBasedirPath($domain['customerroot'], true); - } - - $openbasedir .= appendOpenBasedirPath($tmpdir); - $openbasedir .= $_phpappendopenbasedir; - - $openbasedir = explode(':', $openbasedir); - $clean_openbasedir = array(); - foreach($openbasedir as $number => $path) - { - if(trim($path) != '/') - { - $clean_openbasedir[] = makeCorrectDir($path); - } - } - $openbasedir = implode(':', $clean_openbasedir); - } - else - { - $openbasedir = 'none'; + + $starter_file_handler = fopen($starter_filename, 'w'); + fwrite($starter_file_handler, $starter_file); + fclose($starter_file_handler); + safe_exec('chmod 750 ' . escapeshellarg($starter_filename)); + safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename)); + setImmutable($starter_filename); + + // define the php.ini + + $openbasedir = ''; $openbasedirc = ';'; + + if($domain['openbasedir'] == '1') + { + $openbasedirc = ''; + $_phpappendopenbasedir = ''; + + $_custom_openbasedir = explode(':', $this->settings['system']['mod_fcgid_peardir']); + foreach($_custom_openbasedir as $cobd) + { + $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); + } + + $_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']); + foreach($_custom_openbasedir as $cobd) + { + $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); + } + + if($domain['openbasedir_path'] == '0' && strstr($domain['documentroot'], ":") === false) + { + $openbasedir = appendOpenBasedirPath($domain['documentroot'], true); + } + else + { + $openbasedir = appendOpenBasedirPath($domain['customerroot'], true); + } + + $openbasedir .= appendOpenBasedirPath($tmpdir); + $openbasedir .= $_phpappendopenbasedir; + + $openbasedir = explode(':', $openbasedir); + $clean_openbasedir = array(); + foreach($openbasedir as $number => $path) + { + if(trim($path) != '/') + { + $clean_openbasedir[] = makeCorrectDir($path); + } + } + $openbasedir = implode(':', $clean_openbasedir); + } + else + { + $openbasedir = 'none'; + $openbasedirc = ';'; + } + + $admin = $this->getAdminData($domain['adminid']); + $php_ini_variables = array( + 'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'), + 'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'], + 'OPEN_BASEDIR' => $openbasedir, + 'OPEN_BASEDIR_C' => $openbasedirc, + 'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'], + 'TMP_DIR' => $tmpdir, + 'CUSTOMER_EMAIL' => $domain['email'], + 'ADMIN_EMAIL' => $admin['email'], + 'DOMAIN' => $domain['domain'], + 'CUSTOMER' => $domain['loginname'], + 'ADMIN' => $admin['loginname'] + ); + + //insert a small header for the file + + $phpini_file = ";\n"; + $phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; + $phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; + $phpini_file.= ";\n\n"; + $phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables); + $phpini_file = str_replace('"none"', 'none', $phpini_file); + $phpini_file = preg_replace('/\"+/', '"', $phpini_file); + $phpini_file_handler = fopen($phpini_filename, 'w'); + fwrite($phpini_file_handler, $phpini_file); + fclose($phpini_file_handler); + safe_exec('chown root:0 ' . escapeshellarg($phpini_filename)); + safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename)); } - - $admin = $this->getAdminData($domain['adminid']); - $php_ini_variables = array( - 'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'), - 'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'], - 'OPEN_BASEDIR' => $openbasedir, - 'OPEN_BASEDIR_C' => $openbasedirc, - 'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'], - 'TMP_DIR' => $tmpdir, - 'CUSTOMER_EMAIL' => $domain['email'], - 'ADMIN_EMAIL' => $admin['email'], - 'DOMAIN' => $domain['domain'], - 'CUSTOMER' => $domain['loginname'], - 'ADMIN' => $admin['loginname'] - ); - - //insert a small header for the file - - $phpini_file = ";\n"; - $phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n"; - $phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n"; - $phpini_file.= ";\n\n"; - $phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables); - $phpini_file = str_replace('"none"', 'none', $phpini_file); - $phpini_file = preg_replace('/\"+/', '"', $phpini_file); - $phpini_file_handler = fopen($phpini_filename, 'w'); - fwrite($phpini_file_handler, $phpini_file); - fclose($phpini_file_handler); - safe_exec('chown root:0 ' . escapeshellarg($phpini_filename)); - safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename)); } else { @@ -302,6 +309,78 @@ class lighttpd_fcgid extends lighttpd return $this->admin_cache[$adminid]; } -} -?> + private function _createFpmPart($domain) + { + $php_options_text = ''; + + $socket = makeCorrectFile('/var/run/lighttpd/'.$domain['loginname'].'-'.$domain['domain'].'-php-fpm.socket'); + $tmpfile = makeCorrectFile($this->settings['phpfpm']['configdir'].'/'.$domain['domain'].'.conf'); + + $fh = @fopen($tmpfile, 'w'); + if($fh) + { + $fpm_pm = $this->settings['phpfpm']['pm']; + $fpm_children = (int)$this->settings['phpfpm']['max_children']; + $fpm_start_servers = (int)$this->settings['phpfpm']['start_servers']; + $fpm_min_spare_servers = (int)$this->settings['phpfpm']['min_spare_servers']; + $fpm_max_spare_servers = (int)$this->settings['phpfpm']['max_spare_servers']; + $fpm_requests = (int)$this->settings['phpfpm']['max_requests']; + + if($fpm_children == 0) { + $fpm_children = 1; + } + + $tmpdir = makeCorrectDir($this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/'); + //$slowlog = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . '/php-fpm_slow.log'); + + $fpm_config = ';PHP-FPM configuration for "'.$domain['domain'].'" created on ' . date("Y.m.d H:i:s") . "\n\n"; + $fpm_config.= '['.$domain['domain'].']'."\n"; + $fpm_config.= 'listen = '.$socket."\n"; + $fpm_config.= 'listen.owner = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.group = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.mode = 0666'."\n\n"; + + $fpm_config.= 'user = '.$domain['loginname']."\n"; + $fpm_config.= 'group = '.$domain['loginname']."\n\n"; + + $fpm_config.= 'pm = '.$fpm_pm."\n"; + $fpm_config.= 'pm.max_children = '.$fpm_children."\n"; + if($fpm_pm == 'dynamic') { + $fpm_config.= 'pm.start_servers = '.$fpm_start_servers."\n"; + $fpm_config.= 'pm.min_spare_servers = '.$fpm_min_spare_servers."\n"; + $fpm_config.= 'pm.max_spare_servers = '.$fpm_max_spare_servers."\n"; + } + $fpm_config.= 'pm.max_requests = '.$fpm_requests."\n\n"; + + $fpm_config.= ';chroot = '.makeCorrectDir($domain['documentroot'])."\n\n"; + + $fpm_config.= 'env[TMP] = '.$tmpdir."\n"; + $fpm_config.= 'env[TMPDIR] = '.$tmpdir."\n"; + $fpm_config.= 'env[TEMP] = '.$tmpdir."\n\n"; + + $fpm_config.= 'php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f '.$domain['email']."\n\n"; + $fpm_config.= 'php_admin_value[open_basedir] = ' . $this->settings['system']['documentroot_prefix'] . $domain['loginname'] . '/:' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/:' . $this->settings['phpfpm']['peardir'] . "\n"; + $fpm_config.= 'php_admin_value[session.save_path] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n"; + $fpm_config.= 'php_admin_value[upload_tmp_dir] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n\n"; + + fwrite($fh, $fpm_config, strlen($fpm_config)); + fclose($fh); + + $php_options_text = ' fastcgi.server = ( '."\n"; + $php_options_text.= "\t".'".php" => ('."\n"; + $php_options_text.= "\t\t".'"localhost" => ('."\n"; + $php_options_text.= "\t\t".'"socket" => "'.$socket.'",'."\n"; + $php_options_text.= "\t\t".'"check-local" => "enable",'."\n"; + $php_options_text.= "\t\t".'"disable-time" => 1'."\n"; + $php_options_text.= "\t".')'."\n"; + $php_options_text.= "\t".')'."\n"; + $php_options_text.= ' )'."\n"; + } + else + { + $php_options_text = ' # could not create php-fpm configuration for '.$domain['domain']. "\n"; + } + return $php_options_text; + } +} diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index a683210d..94f704a5 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -64,12 +64,19 @@ class nginx /** * nginx does not auto-spawn fcgi-processes */ - if ($this->settings['system']['phpreload_command'] != '') - { - fwrite($this->debugHandler, ' nginx::reload: restarting php processes' . "\n"); + if ($this->settings['system']['phpreload_command'] != '' + && (int)$this->settings['phpfpm']['enabled'] == 0 + ) { + fwrite($this->debugHandler, ' nginx::reload: restarting php processes' . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'restarting php processes'); safe_exec($this->settings['system']['phpreload_command']); } + elseif((int)$this->settings['phpfpm']['enabled'] == 1) + { + fwrite($this->debugHandler, ' nginx::reload: reloading php-fpm' . "\n"); + $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading php-fpm'); + safe_exec(escapeshellcmd($this->settings['phpfpm']['reload'])); + } } public function createVirtualHosts() @@ -532,7 +539,7 @@ class nginx $phpopts = "\t".'location ~ \.php$ {'."\n"; $phpopts.= "\t\t".'fastcgi_index index.php;'."\n"; $phpopts.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; - $phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root' . '$fastcgi_script_name;'."\n"; + $phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME '.makeCorrectDir($domain['documentroot']).'$fastcgi_script_name;'."\n"; $phpopts.= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n"; $phpopts.= "\t".'}'."\n"; } diff --git a/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php new file mode 100644 index 00000000..088e67b8 --- /dev/null +++ b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php @@ -0,0 +1,156 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Cron + * @version $Id$ + */ + +/* + * This script creates the php.ini's used by mod_suPHP+php-cgi + */ + +if(@php_sapi_name() != 'cli' +&& @php_sapi_name() != 'cgi' +&& @php_sapi_name() != 'cgi-fcgi') +{ + die('This script only works in the shell.'); +} + +class nginx_phpfpm extends nginx +{ + private $php_configs_cache = array(); + private $admin_cache = array(); + + protected function composePhpOptions($domain) + { + $php_options_text = ''; + + if($domain['phpenabled'] == '1') + { + $php_options_text = $this->_createFpmPart($domain); + } + else + { + $php_options_text.= ' # PHP is disabled for this vHost' . "\n"; + } + + return $php_options_text; + } + + private function getPhpConfig($php_config_id) + { + $php_config_id = intval($php_config_id); + + // If domain has no config, we will use the default one. + + if($php_config_id == 0) + { + $php_config_id = 1; + } + + if(!isset($this->php_configs_cache[$php_config_id])) + { + $this->php_configs_cache[$php_config_id] = $this->getDB()->query_first("SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = " . (int)$php_config_id); + } + + return $this->php_configs_cache[$php_config_id]; + } + + private function getAdminData($adminid) + { + $adminid = intval($adminid); + + if(!isset($this->admin_cache[$adminid])) + { + $this->admin_cache[$adminid] = $this->getDB()->query_first("SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = " . (int)$adminid); + } + + return $this->admin_cache[$adminid]; + } + + private function _createFpmPart($domain) + { + $php_options_text = ''; + + if(!is_dir('/var/run/nginx/')) { + safe_exec('mkdir -p /var/run/nginx/'); + safe_exec('chown -R '.$this->settings['system']['httpuser'].':'.$this->settings['system']['httpgroup'].' /var/run/nginx/'); + } + $socket = makeCorrectFile('/var/run/nginx/'.$domain['loginname'].'-'.$domain['domain'].'-php-fpm.socket'); + $tmpfile = makeCorrectFile($this->settings['phpfpm']['configdir'].'/'.$domain['domain'].'.conf'); + + $fh = @fopen($tmpfile, 'w'); + if($fh) + { + $fpm_pm = $this->settings['phpfpm']['pm']; + $fpm_children = (int)$this->settings['phpfpm']['max_children']; + $fpm_start_servers = (int)$this->settings['phpfpm']['start_servers']; + $fpm_min_spare_servers = (int)$this->settings['phpfpm']['min_spare_servers']; + $fpm_max_spare_servers = (int)$this->settings['phpfpm']['max_spare_servers']; + $fpm_requests = (int)$this->settings['phpfpm']['max_requests']; + + if($fpm_children == 0) { + $fpm_children = 1; + } + + $tmpdir = makeCorrectDir($this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/'); + //$slowlog = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . '/php-fpm_slow.log'); + + $fpm_config = ';PHP-FPM configuration for "'.$domain['domain'].'" created on ' . date("Y.m.d H:i:s") . "\n\n"; + $fpm_config.= '['.$domain['domain'].']'."\n"; + $fpm_config.= 'listen = '.$socket."\n"; + $fpm_config.= 'listen.owner = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.group = '.$domain['loginname']."\n"; + $fpm_config.= 'listen.mode = 0666'."\n\n"; + + $fpm_config.= 'user = '.$domain['loginname']."\n"; + $fpm_config.= 'group = '.$domain['loginname']."\n\n"; + + $fpm_config.= 'pm = '.$fpm_pm."\n"; + $fpm_config.= 'pm.max_children = '.$fpm_children."\n"; + if($fpm_pm == 'dynamic') { + $fpm_config.= 'pm.start_servers = '.$fpm_start_servers."\n"; + $fpm_config.= 'pm.min_spare_servers = '.$fpm_min_spare_servers."\n"; + $fpm_config.= 'pm.max_spare_servers = '.$fpm_max_spare_servers."\n"; + } + $fpm_config.= 'pm.max_requests = '.$fpm_requests."\n\n"; + + $fpm_config.= ';chroot = '.makeCorrectDir($domain['documentroot'])."\n\n"; + + $fpm_config.= 'env[TMP] = '.$tmpdir."\n"; + $fpm_config.= 'env[TMPDIR] = '.$tmpdir."\n"; + $fpm_config.= 'env[TEMP] = '.$tmpdir."\n\n"; + + $fpm_config.= 'php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f '.$domain['email']."\n\n"; + $fpm_config.= 'php_admin_value[open_basedir] = ' . $this->settings['system']['documentroot_prefix'] . $domain['loginname'] . '/:' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/:' . $this->settings['phpfpm']['peardir'] . "\n"; + $fpm_config.= 'php_admin_value[session.save_path] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n"; + $fpm_config.= 'php_admin_value[upload_tmp_dir] = ' . $this->settings['phpfpm']['tmpdir'] . '/' . $domain['loginname'] . '/' . "\n\n"; + + fwrite($fh, $fpm_config, strlen($fpm_config)); + fclose($fh); + + $php_options_text = "\t".'location ~ \.php$ {'."\n"; + $php_options_text.= "\t\t".'fastcgi_index index.php;'."\n"; + $php_options_text.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; + $php_options_text.= "\t\t".'fastcgi_param SCRIPT_FILENAME '.makeCorrectDir($domain['documentroot']).'$fastcgi_script_name;'."\n"; + $php_options_text.= "\t\t".'fastcgi_pass unix:' . $socket . ';' . "\n"; + $php_options_text.= "\t".'}'."\n"; + + } + else + { + $php_options_text = ' # could not create php-fpm configuration for '.$domain['domain']. "\n"; + } + return $php_options_text; + } +} diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 9fe19178..f5320753 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -120,11 +120,25 @@ while($row = $db->fetch_array($result_tasks)) } } + // clear php-fpm-configurations prior to re-creation to keep it clean + if ($settings['phpfpm']['enabled'] == '1') + { + $configdir = makeCorrectDir($settings['phpfpm']['configdir']); + + if (is_dir($configdir)) + { + // now get rid of old stuff + //(but append /* so we don't delete the directory) + $configdir.='/*'; + safe_exec('rm -rf '. makeCorrectFile($configdir)); + } + } + if(!isset($webserver)) { if($settings['system']['webserver'] == "apache2") { - if($settings['system']['mod_fcgid'] == 1) + if($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) { $webserver = new apache_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings); } @@ -135,7 +149,7 @@ while($row = $db->fetch_array($result_tasks)) } elseif($settings['system']['webserver'] == "lighttpd") { - if($settings['system']['mod_fcgid'] == 1) + if($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) { $webserver = new lighttpd_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings); } @@ -146,7 +160,14 @@ while($row = $db->fetch_array($result_tasks)) } elseif($settings['system']['webserver'] == "nginx") { - $webserver = new nginx($db, $cronlog, $debugHandler, $idna_convert, $settings); + if($settings['phpfpm']['enabled'] == 1) + { + $webserver = new nginx_phpfpm($db, $cronlog, $debugHandler, $idna_convert, $settings); + } + else + { + $webserver = new nginx($db, $cronlog, $debugHandler, $idna_convert, $settings); + } } }