Path: blob/master/src/applications/config/check/PhabricatorPHPPreflightSetupCheck.php
12262 views
<?php12final class PhabricatorPHPPreflightSetupCheck extends PhabricatorSetupCheck {34public function getDefaultGroup() {5return self::GROUP_PHP;6}78public function isPreflightCheck() {9return true;10}1112protected function executeChecks() {13$version = phpversion();14if (version_compare($version, 7, '>=') &&15version_compare($version, 7.1, '<')) {16$message = pht(17'You are running PHP version %s. PHP versions between 7.0 and 7.1 '.18'are not supported'.19"\n\n".20'PHP removed reqiured signal handling features in '.21'PHP 7.0, and did not restore an equivalent mechanism until PHP 7.1.'.22"\n\n".23'Upgrade to PHP 7.1 or newer (recommended) or downgrade to an older '.24'version of PHP 5 (discouraged).',25$version);2627$this->newIssue('php.version7')28->setIsFatal(true)29->setName(pht('PHP 7.0-7.1 Not Supported'))30->setMessage($message)31->addLink(32'https://phurl.io/u/php7',33pht('PHP 7 Compatibility Information'));3435return;36}3738// TODO: This can be removed entirely because the minimum PHP version is39// now PHP 5.5, which does not have safe mode.4041$safe_mode = ini_get('safe_mode');42if ($safe_mode) {43$message = pht(44"You have '%s' enabled in your PHP configuration, but this software ".45"will not run in safe mode. Safe mode has been deprecated in PHP 5.3 ".46"and removed in PHP 5.4.\n\nDisable safe mode to continue.",47'safe_mode');4849$this->newIssue('php.safe_mode')50->setIsFatal(true)51->setName(pht('Disable PHP %s', 'safe_mode'))52->setMessage($message)53->addPHPConfig('safe_mode');54return;55}5657// Check for `disable_functions` or `disable_classes`. Although it's58// possible to disable a bunch of functions (say, `array_change_key_case()`)59// and classes and still have Phabricator work fine, it's unreasonably60// difficult for us to be sure we'll even survive setup if these options61// are enabled. Phabricator needs access to the most dangerous functions,62// so there is no reasonable configuration value here which actually63// provides a benefit while guaranteeing Phabricator will run properly.6465$disable_options = array('disable_functions', 'disable_classes');66foreach ($disable_options as $disable_option) {67$disable_value = ini_get($disable_option);68if ($disable_value) {6970// By default Debian installs the pcntl extension but disables all of71// its functions using configuration. Whitelist disabling these72// functions so that Debian PHP works out of the box (we do not need to73// call these functions from the web UI). This is pretty ridiculous but74// it's not the users' fault and they haven't done anything crazy to75// get here, so don't make them pay for Debian's unusual choices.76// See: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=60557177$fatal = true;78if ($disable_option == 'disable_functions') {79$functions = preg_split('/[, ]+/', $disable_value);80$functions = array_filter($functions);81foreach ($functions as $k => $function) {82if (preg_match('/^pcntl_/', $function)) {83unset($functions[$k]);84}85}86if (!$functions) {87$fatal = false;88}89}9091if ($fatal) {92$message = pht(93"You have '%s' enabled in your PHP configuration.\n\n".94"This option is not compatible with this software. Remove ".95"'%s' from your configuration to continue.",96$disable_option,97$disable_option);9899$this->newIssue('php.'.$disable_option)100->setIsFatal(true)101->setName(pht('Remove PHP %s', $disable_option))102->setMessage($message)103->addPHPConfig($disable_option);104}105}106}107108$overload_option = 'mbstring.func_overload';109$func_overload = ini_get($overload_option);110if ($func_overload) {111$message = pht(112"You have '%s' enabled in your PHP configuration.\n\n".113"This option is not compatible with this software. Disable ".114"'%s' in your PHP configuration to continue.",115$overload_option,116$overload_option);117118$this->newIssue('php'.$overload_option)119->setIsFatal(true)120->setName(pht('Disable PHP %s', $overload_option))121->setMessage($message)122->addPHPConfig($overload_option);123}124125$open_basedir = ini_get('open_basedir');126if ($open_basedir !== null && strlen($open_basedir)) {127// If `open_basedir` is set, just fatal. It's technically possible for128// us to run with certain values of `open_basedir`, but: we can only129// raise fatal errors from preflight steps, so we'd have to do this check130// in two parts to support fatal and advisory versions; it's much simpler131// to just fatal instead of trying to test all the different things we132// may need to access in the filesystem; and use of this option seems133// rare (particularly in supported environments).134135$message = pht(136"Your server is configured with '%s', which prevents this software ".137"from opening files it requires access to.\n\n".138"Disable this setting to continue.",139'open_basedir');140141$issue = $this->newIssue('php.open_basedir')142->setName(pht('Disable PHP %s', 'open_basedir'))143->addPHPConfig('open_basedir')144->setIsFatal(true)145->setMessage($message);146}147148}149}150151152