Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add custom php.ini files for PHP-FPM to Froxlor 0.9.28-svn5
diff --git actions/admin/settings/136.phpfpm.php actions/admin/settings/136.phpfpm.php
index be0e925..07c73ce 100644
--- actions/admin/settings/136.phpfpm.php
+++ actions/admin/settings/136.phpfpm.php
@@ -54,20 +54,17 @@ return array(
'default' => 'froxlorlocal',
'save_method' => 'storeSettingField'
),
- /*
- * @TODO implement if phpfpm knows custom php.ini files
- *
'system_phpfpm_defaultini_ownvhost' => array(
'label' => $lng['serversettings']['mod_fcgid']['defaultini_ownvhost'],
- 'settinggroup' => 'phpfpm',
- 'varname' => 'vhost_defaultini',
+ 'settinggroup' => 'system',
+ 'varname' => 'mod_fcgid_defaultini_ownvhost',
'type' => 'option',
'default' => '1',
'option_mode' => 'one',
'option_options_method' => 'getPhpConfigs',
'save_method' => 'storeSettingField',
+ 'websrv_avail' => array('apache2', 'apache24')
),
- */
'system_phpfpm_configdir' => array(
'label' => $lng['serversettings']['phpfpm_settings']['configdir'],
'settinggroup' => 'phpfpm',
@@ -77,15 +74,15 @@ return array(
'default' => '/etc/php-fpm.d/',
'save_method' => 'storeSettingField',
),
- 'system_phpfpm_aliasconfigdir' => array(
- 'label' => $lng['serversettings']['phpfpm_settings']['aliasconfigdir'],
- 'settinggroup' => 'phpfpm',
- 'varname' => 'aliasconfigdir',
- 'type' => 'string',
- 'string_type' => 'dir',
- 'default' => '/var/www/php-fpm/',
- 'save_method' => 'storeSettingField',
- ),
+ 'system_phpfpm_aliasconfigdir' => array(
+ 'label' => $lng['serversettings']['phpfpm_settings']['aliasconfigdir'],
+ 'settinggroup' => 'phpfpm',
+ 'varname' => 'aliasconfigdir',
+ 'type' => 'string',
+ 'string_type' => 'dir',
+ 'default' => '/var/www/php-fpm/',
+ 'save_method' => 'storeSettingField',
+ ),
'system_phpfpm_tmpdir' => array(
'label' => $lng['serversettings']['mod_fcgid']['tmpdir'],
'settinggroup' => 'phpfpm',
@@ -104,6 +101,16 @@ return array(
'default' => '/usr/share/php/:/usr/share/php5/',
'save_method' => 'storeSettingField',
),
+ 'system_phpfpm_defaultini' => array(
+ 'label' => $lng['serversettings']['mod_fcgid']['defaultini'],
+ 'settinggroup' => 'system',
+ 'varname' => 'mod_fcgid_defaultini',
+ 'type' => 'option',
+ 'default' => '1',
+ 'option_mode' => 'one',
+ 'option_options_method' => 'getPhpConfigs',
+ 'save_method' => 'storeSettingField',
+ ),
'system_phpfpm_reload' => array(
'label' => $lng['serversettings']['phpfpm_settings']['reload'],
'settinggroup' => 'phpfpm',
diff --git lib/classes/phpinterface/class.phpinterface_fpm.php lib/classes/phpinterface/class.phpinterface_fpm.php
index 1dfc0dd..3762a87 100644
--- lib/classes/phpinterface/class.phpinterface_fpm.php
+++ lib/classes/phpinterface/class.phpinterface_fpm.php
@@ -68,27 +68,41 @@ class phpinterface_fpm
$fpm_config = ';PHP-FPM configuration for "'.$this->_domain['domain'].'" created on ' . date("Y.m.d H:i:s") . "\n";
$fpm_config.= '['.$this->_domain['domain'].']'."\n";
$fpm_config.= 'listen = '.$this->getSocketFile()."\n";
- if($this->_domain['loginname'] == 'froxlor.panel')
- {
- $fpm_config.= 'listen.owner = '.$this->_domain['guid']."\n";
- $fpm_config.= 'listen.group = '.$this->_domain['guid']."\n";
- }
- else
- {
- $fpm_config.= 'listen.owner = '.$this->_domain['loginname']."\n";
- $fpm_config.= 'listen.group = '.$this->_domain['loginname']."\n";
- }
- $fpm_config.= 'listen.mode = 0666'."\n";
-
- if($this->_domain['loginname'] == 'froxlor.panel')
+
+ // try to find out if libnss-mysql is installed
+ // PHP's stat does not work with libnss-mysql
+ $dir_owner = safe_exec('stat -c %U ' . makeCorrectDir($this->_domain['documentroot']));
+
+ if($dir_owner[0] == 'UNKNOWN')
{
+ $fpm_config.= 'listen.mode = 0666'."\n";
$fpm_config.= 'user = '.$this->_domain['guid']."\n";
$fpm_config.= 'group = '.$this->_domain['guid']."\n";
}
else
{
- $fpm_config.= 'user = '.$this->_domain['loginname']."\n";
- $fpm_config.= 'group = '.$this->_domain['loginname']."\n";
+ if($this->_domain['loginname'] == 'froxlor.panel')
+ {
+ $fpm_config.= 'listen.owner = '.$this->_domain['guid']."\n";
+ $fpm_config.= 'listen.group = '.$this->_domain['guid']."\n";
+ }
+ else
+ {
+ $fpm_config.= 'listen.owner = '.$this->_domain['loginname']."\n";
+ $fpm_config.= 'listen.group = '.$this->_domain['loginname']."\n";
+ }
+ $fpm_config.= 'listen.mode = 0666'."\n";
+
+ if($this->_domain['loginname'] == 'froxlor.panel')
+ {
+ $fpm_config.= 'user = '.$this->_domain['guid']."\n";
+ $fpm_config.= 'group = '.$this->_domain['guid']."\n";
+ }
+ else
+ {
+ $fpm_config.= 'user = '.$this->_domain['loginname']."\n";
+ $fpm_config.= 'group = '.$this->_domain['loginname']."\n";
+ }
}
$fpm_config.= 'pm = '.$fpm_pm."\n";
@@ -168,7 +182,96 @@ class phpinterface_fpm
public function createIniFile($phpconfig)
{
- return;
+ if(PHP_VERSION_ID < 50300)
+ {
+ return;
+ }
+
+ $openbasedir = '';
+ $openbasedirc = ';';
+
+ if($this->_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($this->_domain['openbasedir_path'] == '0' && strstr($this->_domain['documentroot'], ":") === false)
+ {
+ $openbasedir = appendOpenBasedirPath($this->_domain['documentroot'], true);
+ }
+ else
+ {
+ $openbasedir = appendOpenBasedirPath($this->_domain['customerroot'], true);
+ }
+
+ $openbasedir .= appendOpenBasedirPath($this->getTempDir());
+ $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($this->_domain['adminid']);
+ $php_ini_variables = array(
+ 'SAFE_MODE' => ($this->_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' => $this->getTempDir(),
+ 'CUSTOMER_EMAIL' => $this->_domain['email'],
+ 'ADMIN_EMAIL' => $admin['email'],
+ 'DOMAIN' => $this->_domain['domain'],
+ 'CUSTOMER' => $this->_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 '" . $this->_domain['domain'] . "' with id #" . $this->_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.= "[PATH=" . makeCorrectDir($this->_domain['documentroot']) . "]\n\n";
+ $phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables);
+ $phpini_file.= "\n[PHP]\n";
+
+ // remove deprecated INI directives
+ $deprecated = array('safe_mode = On', 'safe_mode = Off');
+ $phpini_file = str_replace($deprecated, '', $phpini_file);
+
+ $phpini_file = str_replace('"none"', 'none', $phpini_file);
+ $phpini_file = preg_replace('/\"+/', '"', $phpini_file);
+ $phpini_file_handler = fopen($this->getIniFile(), 'w');
+ fwrite($phpini_file_handler, $phpini_file);
+ fclose($phpini_file_handler);
+ safe_exec('chown root:0 ' . escapeshellarg($this->getIniFile()));
+ safe_exec('chmod 0644 ' . escapeshellarg($this->getIniFile()));
}
/**
@@ -233,7 +336,7 @@ class phpinterface_fpm
return $tmpdir;
}
- /**
+ /**
* fastcgi-fakedirectory directory
*
* @param boolean $createifnotexists create the directory if it does not exist
@@ -256,4 +359,40 @@ class phpinterface_fpm
return $configdir;
}
+
+ /**
+ * return path of php.ini file
+ *
+ * @return string full with path file-name
+ */
+ public function getIniFile()
+ {
+ $php_info = getPhpInfo();
+ $php_ini_scanned_dir = $php_info['Scan this dir for additional .ini files'];
+ $phpini_filename = makeCorrectFile($php_ini_scanned_dir.'/'.$this->_domain['loginname'].'-'.$this->_domain['domain'].'-froxlor-php.ini');
+
+ return $phpini_filename;
+ }
+
+ /**
+ * return the admin-data of a specific admin
+ *
+ * @param int $adminid id of the admin-user
+ *
+ * @return array
+ */
+ private function _getAdminData($adminid)
+ {
+ $adminid = intval($adminid);
+
+ if(!isset($this->_admin_cache[$adminid]))
+ {
+ $this->_admin_cache[$adminid] = $this->_db->query_first(
+ "SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "`
+ WHERE `adminid` = " . (int)$adminid
+ );
+ }
+
+ return $this->_admin_cache[$adminid];
+ }
}
diff --git lib/formfields/admin/domains/formfield.domains_add.php lib/formfields/admin/domains/formfield.domains_add.php
index b90885e..9cb1e10 100644
--- lib/formfields/admin/domains/formfield.domains_add.php
+++ lib/formfields/admin/domains/formfield.domains_add.php
@@ -170,7 +170,7 @@ return array(
'value' => array('1')
),
'phpsettingid' => array(
- 'visible' => ((int)$settings['system']['mod_fcgid'] == 1 ? true : false),
+ 'visible' => ((int)$settings['system']['mod_fcgid'] == 1 || (int)$settings['phpfpm']['enabled'] == 1 ? true : false),
'label' => $lng['admin']['phpsettings']['title'],
'type' => 'select',
'select_var' => $phpconfigs
diff --git lib/formfields/admin/domains/formfield.domains_edit.php lib/formfields/admin/domains/formfield.domains_edit.php
index 616da10..5f20a7f 100644
--- lib/formfields/admin/domains/formfield.domains_edit.php
+++ lib/formfields/admin/domains/formfield.domains_edit.php
@@ -192,7 +192,7 @@ return array(
'value' => array($result['safemode'])
),
'phpsettingid' => array(
- 'visible' => ((int)$settings['system']['mod_fcgid'] == 1 ? true : false),
+ 'visible' => ((int)$settings['system']['mod_fcgid'] == 1 || (int)$settings['phpfpm']['enabled'] == 1 ? true : false),
'label' => $lng['admin']['phpsettings']['title'],
'type' => 'select',
'select_var' => $phpconfigs
diff --git lib/functions/filedir/function.getPhpInfo.php lib/functions/filedir/function.getPhpInfo.php
new file mode 100644
index 0000000..d1e5be9
--- /dev/null
+++ lib/functions/filedir/function.getPhpInfo.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * convert the output of phpinfo into an array
+ *
+ * @return array the phpinfo values
+ */
+
+function getPhpInfo()
+{
+ ob_start();
+ phpinfo();
+ $info_arr = array();
+ $info_lines = explode("\n", ob_get_clean());
+
+ foreach($info_lines as $line)
+ {
+ if(preg_match('/(.+)=>(.+)/', $line, $val))
+ {
+ $info_arr[trim($val[1])] = trim($val[2]);
+ }
+ }
+
+ return $info_arr;
+}
diff --git lib/functions/filedir/function.safe_exec.php lib/functions/filedir/function.safe_exec.php
index 97b3b55..27e8fc7 100644
--- lib/functions/filedir/function.safe_exec.php
+++ lib/functions/filedir/function.safe_exec.php
@@ -57,7 +57,8 @@ function safe_exec($exec_string, &$return_value = false)
'php',
'rm',
'awstats_buildstaticpages.pl',
- 'ln'
+ 'ln',
+ 'stat'
);
//
diff --git scripts/jobs/cron_tasks.php scripts/jobs/cron_tasks.php
index 75fe606..d9cb7e8 100644
--- scripts/jobs/cron_tasks.php
+++ scripts/jobs/cron_tasks.php
@@ -137,6 +137,21 @@ while($row = $db->fetch_array($result_tasks))
safe_exec('rm -rf '. escapeshellarg(makeCorrectFile($configdir)));
}
}
+
+ // clear php INI files prior to re-creation to keep it clean
+ if ($settings['phpfpm']['enabled'] == '1' && PHP_VERSION_ID >= 50300)
+ {
+ $php_info = getPhpInfo();
+ $php_ini_scanned_dir = makeCorrectDir($php_info['Scan this dir for additional .ini files']);
+
+ if (is_dir($php_ini_scanned_dir))
+ {
+ // now get rid of old stuff
+ //(but append /*-froxlor-php.ini so we only delete files created by Froxlor)
+ $php_ini_scanned_dir.='/*froxlor-php.ini';
+ safe_exec('rm -rf '. makeCorrectFile($php_ini_scanned_dir)); // don't use escapeshellarg it will not work, don't worry the path is hardcoded
+ }
+ }
if(!isset($webserver))
{
diff --git lib/classes/phpinterface/class.phpinterface_fpm.php lib/classes/phpinterface/class.phpinterface_fpm.php
index 3762a87..99c9a77 100644
--- lib/classes/phpinterface/class.phpinterface_fpm.php
+++ lib/classes/phpinterface/class.phpinterface_fpm.php
@@ -195,7 +195,7 @@ class phpinterface_fpm
$openbasedirc = '';
$_phpappendopenbasedir = '';
- $_custom_openbasedir = explode(':', $this->_settings['system']['mod_fcgid_peardir']);
+ $_custom_openbasedir = explode(':', $this->_settings['phpfpm']['peardir']);
foreach($_custom_openbasedir as $cobd)
{
$_phpappendopenbasedir .= appendOpenBasedirPath($cobd);
@@ -239,7 +239,7 @@ class phpinterface_fpm
$admin = $this->_getAdminData($this->_domain['adminid']);
$php_ini_variables = array(
'SAFE_MODE' => ($this->_domain['safemode'] == '0' ? 'Off' : 'On'),
- 'PEAR_DIR' => $this->_settings['system']['mod_fcgid_peardir'],
+ 'PEAR_DIR' => $this->_settings['phpfpm']['peardir'],
'OPEN_BASEDIR' => $openbasedir,
'OPEN_BASEDIR_C' => $openbasedirc,
'OPEN_BASEDIR_GLOBAL' => $this->_settings['system']['phpappendopenbasedir'],
diff --git lib/navigation/00.froxlor.main.php lib/navigation/00.froxlor.main.php
index de11bfa..60bfe7b 100644
--- lib/navigation/00.froxlor.main.php
+++ lib/navigation/00.froxlor.main.php
@@ -249,11 +249,7 @@ return array (
'label' => $lng['menue']['phpsettings']['maintitle'],
'show_element' => (
getSetting('system', 'mod_fcgid') == true
- /*
- * @TODO activate if phpfpm knows custom php.ini files
- *
- * || getSetting('phpfpm', 'enabled') == true
- */
+ || getSetting('phpfpm', 'enabled') == true
),
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment