diff --git a/overrides/symfony/process/PhpExecutableFinder.php b/overrides/symfony/process/PhpExecutableFinder.php index a6ce5c636..bbd2e2e74 100644 --- a/overrides/symfony/process/PhpExecutableFinder.php +++ b/overrides/symfony/process/PhpExecutableFinder.php @@ -27,19 +27,53 @@ class PhpExecutableFinder //$this->executableFinder = new ExecutableFinder(); } + public function getPhpPath() + { + if ($this->isCpanel()) { + return '/usr/local/bin/php'; + } + + return 'php'; + } + public function isCpanel() { - return is_dir('/usr/local/cpanel'); + return $this->checkFolderAndPort('/usr/local/cpanel', 2082); } public function isPlesk() { - return is_dir('/usr/local/psa'); + return $this->checkFolderAndPort('/usr/local/psa', 8443); } public function isVirtualmin() { - return is_dir('/usr/share/webmin'); + return $this->checkFolderAndPort('/usr/share/webmin', 10000); + } + + public function checkFolderAndPort($folder, $port) + { + try { + return is_dir($folder); + } catch (\ErrorException | \Exception | \Throwable $e) { + return $this->checkSocket($port); + } + } + + public function checkSocket($port) + { + try { + $ip = @gethostbyname('localhost'); + $link = @fsockopen($ip, $port, $errno, $error); + + if ($link) { + return true; + } + + return false; + } catch (\ErrorException | \Exception | \Throwable $e) { + return false; + } } /** @@ -51,11 +85,7 @@ class PhpExecutableFinder { # @override // Not working on shared hosting due to "open_basedir" restriction applied by cPanel/Plesk - if ($this->isCpanel()) { - return '/usr/local/bin/php'; - } else { - return 'php'; - } + return $this->getPhpPath(); if ($php = getenv('PHP_BINARY')) { if (!is_executable($php)) {