- implement php-fpm for Froxlor-vhost, fixes #505
This commit is contained in:
@@ -246,6 +246,35 @@ class apache
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' </Directory>' . "\n";
|
||||
}
|
||||
}
|
||||
// create php-fpm <Directory>-Part (config is created in apache_fcgid)
|
||||
elseif($this->settings['phpfpm']['enabled'] == '1')
|
||||
{
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $this->settings['phpfpm']['vhost_httpuser'],
|
||||
'openbasedir' => 0,
|
||||
'safemode' => '0',
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath
|
||||
);
|
||||
|
||||
$php = new phpinterface($this->getDB(), $this->settings, $domain);
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' FastCgiExternalServer ' . $mypath . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $this->settings['system']['mod_fcgid_httpuser'] . ' -group ' . $this->settings['system']['mod_fcgid_httpuser'] . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' <Directory "' . $mypath . '">' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' AddHandler php5-fastcgi .php'. "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' Action php5-fastcgi /fastcgiphp' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' Options +ExecCGI' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' Order allow,deny' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' allow from all' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' </Directory>' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' Alias /fastcgiphp ' . $mypath . 'fpm.external' . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* dirprotection, see #72
|
||||
|
||||
@@ -89,114 +89,54 @@ class apache_fcgid extends apache
|
||||
|
||||
public function createOwnVhostStarter()
|
||||
{
|
||||
if ($this->settings['system']['mod_fcgid_ownvhost'] == '1')
|
||||
{
|
||||
if ($this->settings['system']['mod_fcgid_ownvhost'] == '1'
|
||||
|| ($this->settings['phpfpm']['enabled'] == '1'
|
||||
&& $this->settings['phpfpm']['enabled_ownvhost'] == '1')
|
||||
) {
|
||||
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); // /var/www/froxlor, needed for chown
|
||||
$configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/froxlor.panel/');
|
||||
$starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter');
|
||||
$phpini_filename = makeCorrectFile($configdir . '/php.ini');
|
||||
$tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/froxlor.panel/');
|
||||
|
||||
$user = $this->settings['system']['mod_fcgid_httpuser'];
|
||||
$group = $this->settings['system']['mod_fcgid_httpgroup'];
|
||||
|
||||
if ($this->settings['system']['mod_fcgid_ownvhost'] == '1')
|
||||
{
|
||||
$user = $this->settings['system']['mod_fcgid_httpuser'];
|
||||
$group = $this->settings['system']['mod_fcgid_httpgroup'];
|
||||
}
|
||||
elseif($this->settings['phpfpm']['enabled'] == '1'
|
||||
&& $this->settings['phpfpm']['enabled_ownvhost'] == '1'
|
||||
) {
|
||||
$user = $this->settings['phpfpm']['vhost_httpuser'];
|
||||
$group = $this->settings['phpfpm']['vhost_httpgroup'];
|
||||
}
|
||||
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $user,
|
||||
'openbasedir' => 0,
|
||||
'safemode' => '0',
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath
|
||||
);
|
||||
|
||||
// all the files and folders have to belong to the local user
|
||||
// now because we also use fcgid for our own vhost
|
||||
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath));
|
||||
|
||||
// create config dir if necessary
|
||||
if(!is_dir($configdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($configdir));
|
||||
safe_exec('chown ' . $user . ':' . $group . ' ' . escapeshellarg($configdir));
|
||||
}
|
||||
|
||||
// create tmp dir if necessary
|
||||
if(!is_dir($tmpdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chmod 0750 ' . escapeshellarg($tmpdir));
|
||||
}
|
||||
|
||||
|
||||
// get php.ini for our own vhost
|
||||
$php = new phpinterface($this->getDB(), $this->settings, null);
|
||||
$php = new phpinterface($this->getDB(), $this->settings, $domain);
|
||||
|
||||
// @FIXME don't use fcgid settings if not fcgid in use, but we don't have anything else atm
|
||||
$phpconfig = $php->getPhpConfig($this->settings['system']['mod_fcgid_defaultini_ownvhost']);
|
||||
|
||||
// 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 the Froxlor vhost\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";
|
||||
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";
|
||||
}
|
||||
$starter_file.= "export PHP_FCGI_CHILDREN\n";
|
||||
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 ' . $user . ':' . $group . ' ' . escapeshellarg($starter_filename));
|
||||
setImmutable($starter_filename);
|
||||
|
||||
// define the php.ini
|
||||
|
||||
$php_ini_variables = array(
|
||||
'SAFE_MODE' => 'Off',
|
||||
'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'],
|
||||
'OPEN_BASEDIR' => 'none',
|
||||
'OPEN_BASEDIR_C' => ';',
|
||||
'OPEN_BASEDIR_GLOBAL' => '',
|
||||
'TMP_DIR' => $tmpdir,
|
||||
'CUSTOMER_EMAIL' => $this->settings['panel']['adminmail'],
|
||||
'ADMIN_EMAIL' => $this->settings['panel']['adminmail'],
|
||||
'DOMAIN' => $this->settings['system']['hostname'],
|
||||
'CUSTOMER' => $user,
|
||||
'ADMIN' => $user
|
||||
);
|
||||
|
||||
//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 Froxlor-vhost 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));
|
||||
// create starter-file | config-file
|
||||
$php->getInterface()->createConfig($phpconfig);
|
||||
|
||||
// create php.ini
|
||||
// @TODO make php-fpm support this
|
||||
$php->getInterface()->createIniFile($phpconfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,38 @@ class lighttpd
|
||||
$this->lighttpd_data[$vhost_filename].= ' }' . "\n";
|
||||
*/
|
||||
|
||||
/**
|
||||
* own php-fpm vhost
|
||||
*/
|
||||
if((int)$this->settings['phpfpm']['enabled'] == 1)
|
||||
{
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $this->settings['phpfpm']['vhost_httpuser'],
|
||||
'openbasedir' => 0,
|
||||
'safemode' => '0',
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath
|
||||
);
|
||||
|
||||
$php = new phpinterface($this->getDB(), $this->settings, $domain);
|
||||
|
||||
$this->lighttpd_data[$vhost_filename].= ' fastcgi.server = ( '."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t".'".php" => ('."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t\t".'"localhost" => ('."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t\t".'"socket" => "'.$php->getInterface()->getSocketFile().'",'."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t\t".'"check-local" => "enable",'."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t\t".'"disable-time" => 1'."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t".')'."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= "\t".')'."\n";
|
||||
$this->lighttpd_data[$vhost_filename].= ' )'."\n";
|
||||
}
|
||||
|
||||
if($row_ipsandports['specialsettings'] != '')
|
||||
{
|
||||
$this->lighttpd_data[$vhost_filename].= $row_ipsandports['specialsettings'] . "\n";
|
||||
|
||||
@@ -228,8 +228,30 @@ class nginx
|
||||
$this->nginx_data[$vhost_filename].= "\t".'location ~ \.php$ {'."\n";
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_index index.php;'."\n";
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'include /etc/nginx/fastcgi_params;'."\n";
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root' . '$fastcgi_script_name;'."\n";
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n";
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n";
|
||||
if((int)$this->settings['phpfpm']['enabled'] == 1)
|
||||
{
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $this->settings['phpfpm']['vhost_httpuser'],
|
||||
'openbasedir' => 0,
|
||||
'safemode' => '0',
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath
|
||||
);
|
||||
|
||||
$php = new phpinterface($this->getDB(), $this->settings, $domain);
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n";
|
||||
}
|
||||
$this->nginx_data[$vhost_filename].= "\t".'}'."\n";
|
||||
|
||||
$this->nginx_data[$vhost_filename].= '}' . "\n\n";
|
||||
@@ -539,7 +561,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 '.makeCorrectDir($domain['documentroot']).'$fastcgi_script_name;'."\n";
|
||||
$phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n";
|
||||
$phpopts.= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n";
|
||||
$phpopts.= "\t".'}'."\n";
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class nginx_phpfpm extends nginx
|
||||
$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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n";
|
||||
$php_options_text.= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n";
|
||||
$php_options_text.= "\t".'}'."\n";
|
||||
|
||||
@@ -58,4 +58,47 @@ class nginx_phpfpm extends nginx
|
||||
|
||||
return $php_options_text;
|
||||
}
|
||||
|
||||
public function createOwnVhostStarter()
|
||||
{
|
||||
if ($this->settings['phpfpm']['enabled'] == '1'
|
||||
&& $this->settings['phpfpm']['enabled_ownvhost'] == '1'
|
||||
) {
|
||||
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); // /var/www/froxlor, needed for chown
|
||||
|
||||
$user = $this->settings['phpfpm']['vhost_httpuser'];
|
||||
$group = $this->settings['phpfpm']['vhost_httpgroup'];
|
||||
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $user,
|
||||
'openbasedir' => 0,
|
||||
'safemode' => '0',
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath
|
||||
);
|
||||
|
||||
// all the files and folders have to belong to the local user
|
||||
// now because we also use fcgid for our own vhost
|
||||
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath));
|
||||
|
||||
// get php.ini for our own vhost
|
||||
$php = new phpinterface($this->getDB(), $this->settings, $domain);
|
||||
|
||||
// @FIXME don't use fcgid settings, but we don't have anything else atm
|
||||
$phpconfig = $php->getPhpConfig($this->settings['system']['mod_fcgid_defaultini_ownvhost']);
|
||||
|
||||
// create starter-file | config-file
|
||||
$php->getInterface()->createConfig($phpconfig);
|
||||
|
||||
// create php.ini
|
||||
// @TODO make php-fpm support this
|
||||
$php->getInterface()->createIniFile($phpconfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user