diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php index e50333ec7..db139cf79 100644 --- a/modules/setup/application/clicommands/ConfigCommand.php +++ b/modules/setup/application/clicommands/ConfigCommand.php @@ -102,7 +102,11 @@ class ConfigCommand extends Command * * --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] + * --fpm-url= Address where to pass requests to FPM [127.0.0.1:9000] + * + * --fpm-uri= Alias for --fpm-url + * + * --fpm-socket-path= Socket path where to pass requests to FPM, overrides --fpm-url * * --config= Path to Icinga Web 2's configuration files [/etc/icingaweb2] * @@ -120,9 +124,13 @@ class ConfigCommand extends Command * icingacli setup config webserver apache \ * --file=/etc/apache2/conf.d/icingaweb2.conf * + * icingacli setup config webserver apache \ + * --file=/etc/apache2/conf.d/icingaweb2.conf + * --fpm-url=localhost:9000 + * * icingacli setup config webserver nginx \ * --root=/usr/share/icingaweb2/public \ - * --fpm-uri=unix:/var/run/php5-fpm.sock + * --fpm-socket-path=/var/run/php8.3-fpm.sock */ public function webserverAction() { @@ -157,10 +165,18 @@ class ConfigCommand extends Command $enableFpm = $this->params->shift('enable-fpm', $webserver->getEnableFpm()); - $fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri())); - if (empty($fpmUri)) { + $fpmSocketPath = trim($this->params->get('fpm-socket-path', $webserver->getFpmSocketPath())); + $fpmUrl = trim($this->params->get('fpm-url', $webserver->getFpmUrl())); + if (empty($fpmUrl)) { + $fpmUrl = trim($this->params->get('fpm-uri', $webserver->getFpmUrl())); + } + if (empty($fpmSocketPath) && empty($fpmUrl)) { $this->fail($this->translate( - 'The argument --fpm-uri expects an address or path where to pass requests to FPM' + 'One of the arguments --fpm-socket-path or --fpm-url must be set to pass requests to FPM' + )); + } elseif (!empty($fpmSocketPath) && !empty($fpmUrl)) { + $this->fail($this->translate( + 'Only one of the arguments --fpm-socket-path or --fpm-url must be set to pass requests to FPM' )); } $webserver @@ -168,7 +184,8 @@ class ConfigCommand extends Command ->setConfigDir($configDir) ->setUrlPath($urlPath) ->setEnableFpm($enableFpm) - ->setFpmUri($fpmUri); + ->setFpmUrl($fpmUrl) + ->setFpmSocketPath($fpmSocketPath); $config = $webserver->generate() . "\n"; if (($file = $this->params->get('file')) !== null) { if (file_exists($file) === true) { diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php index 77ff23776..cca0fcdd6 100644 --- a/modules/setup/library/Setup/Webserver.php +++ b/modules/setup/library/Setup/Webserver.php @@ -33,11 +33,25 @@ abstract class Webserver protected $configDir; /** - * Address or path where to pass requests to FPM + * Address where to pass requests to FPM * * @var string */ - protected $fpmUri; + protected $fpmUrl; + + /** + * Socket path where to pass requests to FPM + * + * @var string + */ + protected $fpmSocketPath; + + /** + * FPM socket connection schema + * + * @var string + */ + protected $fpmSocketSchema = 'unix:'; /** * Enable to pass requests to FPM @@ -72,6 +86,7 @@ abstract class Webserver public function generate() { $template = $this->getTemplate(); + $fpmUri = $this->createFpmUri(); $searchTokens = array( '{urlPath}', @@ -85,7 +100,7 @@ abstract class Webserver $this->getDocumentRoot(), preg_match('~/$~', $this->getUrlPath()) ? $this->getDocumentRoot() . '/' : $this->getDocumentRoot(), $this->getConfigDir(), - $this->getFpmUri() + $fpmUri ); $template = str_replace($searchTokens, $replaceTokens, $template); return $template; @@ -98,6 +113,13 @@ abstract class Webserver */ abstract protected function getTemplate(); + /** + * Creates the connection string for the respective web server + * + * @return string + */ + abstract protected function createFpmUri(); + /** * Set the URL path of Icinga Web 2 * @@ -208,25 +230,47 @@ abstract class Webserver } /** - * Get the address or path where to pass requests to FPM + * Get the address where to pass requests to FPM * * @return string */ - public function getFpmUri() + public function getFpmUrl() { - return $this->fpmUri; + return $this->fpmUrl; } /** - * Set the address or path where to pass requests to FPM + * Set the address where to pass requests to FPM * - * @param string $uri + * @param string $url * * @return $this */ - public function setFpmUri($uri) + public function setFpmUrl($url) { - $this->fpmUri = (string) $uri; + $this->fpmUrl = (string) $url; + + return $this; + } + + /** + * Get the socket path where to pass requests to FPM + * + * @return string + */ + public function getFpmSocketPath() + { + return $this->fpmSocketPath; + } + + /** + * Set the socket path where to pass requests to FPM + * + * @return $this + */ + public function setFpmSocketPath($socketPath) + { + $this->fpmSocketPath = (string) $socketPath; return $this; } diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php index fdb367f8f..00212ffec 100644 --- a/modules/setup/library/Setup/Webserver/Apache.php +++ b/modules/setup/library/Setup/Webserver/Apache.php @@ -10,7 +10,21 @@ use Icinga\Module\Setup\Webserver; */ class Apache extends Webserver { - protected $fpmUri = '127.0.0.1:9000'; + protected $fpmUrl = '127.0.0.1:9000'; + + protected $fpmUrlSchema = 'fcgi://'; + + protected function createFpmUri() + { + $apacheFpmUri = ""; + if (empty($this->fpmSocketPath)) { + $apacheFpmUri = $this->fpmUrlSchema . $this->fpmUrl; + } else { + $apacheFpmUri = $this->fpmSocketSchema . $this->fpmSocketPath . '|' . $this->fpmUrlSchema . 'localhost'; + } + + return $apacheFpmUri; + } protected function getTemplate() { @@ -23,7 +37,7 @@ Alias {urlPath} "{aliasDocumentRoot}" # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # -# ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1" +# ProxyPassMatch "{fpmUri}/{documentRoot}/$1" # # @@ -71,7 +85,7 @@ Alias {urlPath} "{aliasDocumentRoot}" # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # -# SetHandler "proxy:fcgi://{fpmUri}" +# SetHandler "proxy:{fpmUri}" # ErrorDocument 503 {urlPath}/error_unavailable.html # # @@ -85,7 +99,7 @@ Alias {urlPath} "{aliasDocumentRoot}" # Forward PHP requests to FPM SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 - ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1" + ProxyPassMatch "{fpmUri}/{documentRoot}/$1" @@ -131,7 +145,7 @@ Alias {urlPath} "{aliasDocumentRoot}" # Forward PHP requests to FPM SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 - SetHandler "proxy:fcgi://{fpmUri}" + SetHandler "proxy:{fpmUri}" ErrorDocument 503 {urlPath}/error_unavailable.html diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php index c7ae71688..dea302ab9 100644 --- a/modules/setup/library/Setup/Webserver/Nginx.php +++ b/modules/setup/library/Setup/Webserver/Nginx.php @@ -10,10 +10,15 @@ use Icinga\Module\Setup\Webserver; */ class Nginx extends Webserver { - protected $fpmUri = '127.0.0.1:9000'; + protected $fpmUrl = '127.0.0.1:9000'; protected $enableFpm = true; + protected function createFpmUri() + { + return empty($this->fpmSocketPath) ? $this->fpmUrl : $this->fpmSocketSchema . $this->fpmSocketPath; + } + protected function getTemplate() { return <<<'EOD'