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