diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php index ae43fe5e0..130d7970c 100644 --- a/modules/setup/application/clicommands/ConfigCommand.php +++ b/modules/setup/application/clicommands/ConfigCommand.php @@ -99,6 +99,8 @@ class ConfigCommand extends Command * --root|--document-root= The directory from which the webserver will serve files * [/path/to/icingaweb2/public] * + * --enable-fpm Enable FPM handler for Apache (Nginx is always enabled) + * * --fpm-uri= Address or path where to pass requests to FPM [127.0.0.1:9000] * * --config= Path to Icinga Web 2's configuration files [/etc/icingaweb2] @@ -149,6 +151,9 @@ class ConfigCommand extends Command 'The argument --config expects a path to Icinga Web 2\'s configuration files' )); } + + $enableFpm = $this->params->shift('enable-fpm', $webserver->getEnableFpm()); + $fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri())); if (empty($fpmUri)) { $this->fail($this->translate( @@ -159,6 +164,7 @@ class ConfigCommand extends Command ->setDocumentRoot($documentRoot) ->setConfigDir($configDir) ->setUrlPath($urlPath) + ->setEnableFpm($enableFpm) ->setFpmUri($fpmUri); $config = $webserver->generate() . "\n"; if (($file = $this->params->get('file')) !== null) { diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php index 2dac061a5..145a3c9a1 100644 --- a/modules/setup/library/Setup/Webserver.php +++ b/modules/setup/library/Setup/Webserver.php @@ -39,6 +39,13 @@ abstract class Webserver */ protected $fpmUri; + /** + * Enable to pass requests to FPM + * + * @var bool + */ + protected $enableFpm = false; + /** * Create instance by type name * @@ -174,6 +181,30 @@ abstract class Webserver return $this->configDir; } + /** + * Get whether FPM is enabled + * + * @return bool + */ + public function getEnableFpm() + { + return $this->enableFpm; + } + + /** + * Set FPM enabled + * + * @param bool $flag + * + * @return $this + */ + public function setEnableFpm($flag) + { + $this->enableFpm = (bool) $flag; + + return $this; + } + /** * Get the address or path where to pass requests to FPM * diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php index b3b7620fa..57c8513a6 100644 --- a/modules/setup/library/Setup/Webserver/Apache.php +++ b/modules/setup/library/Setup/Webserver/Apache.php @@ -10,10 +10,11 @@ use Icinga\Module\Setup\Webserver; */ class Apache extends Webserver { - protected $fpmUri = 'fcgi://127.0.0.1:9000'; + protected $fpmUri = '127.0.0.1:9000'; protected function getTemplate() { + if (! $this->enableFpm) { return <<<'EOD' Alias {urlPath} "{documentRoot}" @@ -22,7 +23,7 @@ Alias {urlPath} "{documentRoot}" # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # -# ProxyPassMatch "fcgi://127.0.0.1:9000/{documentRoot}/$1" +# ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1" # # @@ -70,11 +71,72 @@ Alias {urlPath} "{documentRoot}" # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # -# SetHandler "proxy:{fpmUri}" +# SetHandler "proxy:fcgi://{fpmUri}" # ErrorDocument 503 {urlPath}/error_unavailable.html # # EOD; + } else { + return <<<'EOD' +Alias {urlPath} "{documentRoot}" + + + # Forward PHP requests to FPM + SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 + + ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1" + + + + + Options SymLinksIfOwnerMatch + AllowOverride None + + DirectoryIndex index.php + + + # Apache 2.4 + + Require all granted + + + + + # Apache 2.2 + Order allow,deny + Allow from all + + + SetEnv ICINGAWEB_CONFIGDIR "{configDir}" + + EnableSendfile Off + + + RewriteEngine on + RewriteBase {urlPath}/ + RewriteCond %{REQUEST_FILENAME} -s [OR] + RewriteCond %{REQUEST_FILENAME} -l [OR] + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^.*$ - [NC,L] + RewriteRule ^.*$ index.php [NC,L] + + + + DirectoryIndex error_norewrite.html + ErrorDocument 404 {urlPath}/error_norewrite.html + + + = 2.4> + # Forward PHP requests to FPM + SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 + + SetHandler "proxy:fcgi://{fpmUri}" + ErrorDocument 503 {urlPath}/error_unavailable.html + + + +EOD; + } } } diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php index 1223c554d..c7ae71688 100644 --- a/modules/setup/library/Setup/Webserver/Nginx.php +++ b/modules/setup/library/Setup/Webserver/Nginx.php @@ -12,6 +12,8 @@ class Nginx extends Webserver { protected $fpmUri = '127.0.0.1:9000'; + protected $enableFpm = true; + protected function getTemplate() { return <<<'EOD'