Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PhpReadinessCheck.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Model;
7 
8 use Composer\Package\Version\VersionParser;
12 
17 {
21  private $composerInformation;
22 
26  private $phpInformation;
27 
31  private $versionParser;
32 
38  protected $dataSize;
39 
48  public function __construct(
49  ComposerInformation $composerInformation,
50  PhpInformation $phpInformation,
51  VersionParser $versionParser,
53  ) {
54  $this->composerInformation = $composerInformation;
55  $this->phpInformation = $phpInformation;
56  $this->versionParser = $versionParser;
57  $this->dataSize = $dataSize;
58  }
59 
65  public function checkPhpVersion()
66  {
67  try {
68  $requiredVersion = $this->composerInformation->getRequiredPhpVersion();
69  } catch (\Exception $e) {
70  return [
72  'data' => [
73  'error' => 'phpVersionError',
74  'message' => 'Cannot determine required PHP version: ' . $e->getMessage()
75  ],
76  ];
77  }
78  $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion);
79  $normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
80  $currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
82  if (!$multipleConstraints->matches($currentPhpVersion)) {
84  }
85  return [
86  'responseType' => $responseType,
87  'data' => [
88  'required' => $requiredVersion,
89  'current' => PHP_VERSION,
90  ],
91  ];
92  }
93 
99  public function checkPhpSettings()
100  {
102 
103  $settings = array_merge(
104  $this->checkXDebugNestedLevel(),
105  $this->checkPopulateRawPostSetting(),
106  $this->checkFunctionsExistence()
107  );
108 
109  foreach ($settings as $setting) {
110  if ($setting['error']) {
112  }
113  }
114 
115  return [
116  'responseType' => $responseType,
117  'data' => $settings
118  ];
119  }
120 
126  public function checkPhpCronSettings()
127  {
129 
130  $settings = array_merge(
131  $this->checkXDebugNestedLevel(),
132  $this->checkMemoryLimit()
133  );
134 
135  foreach ($settings as $setting) {
136  if ($setting['error']) {
138  }
139  }
140 
141  return [
142  'responseType' => $responseType,
143  'data' => $settings
144  ];
145  }
146 
152  public function checkPhpExtensions()
153  {
154  try {
155  $required = $this->composerInformation->getRequiredExtensions();
156  $current = $this->phpInformation->getCurrent();
157  } catch (\Exception $e) {
158  return [
160  'data' => [
161  'error' => 'phpExtensionError',
162  'message' => 'Cannot determine required PHP extensions: ' . $e->getMessage()
163  ],
164  ];
165  }
167  $missing = array_values(array_diff($required, $current));
168  if ($missing) {
170  }
171  return [
172  'responseType' => $responseType,
173  'data' => [
174  'required' => $required,
175  'missing' => $missing,
176  ],
177  ];
178  }
179 
184  public function checkMemoryLimit()
185  {
186  $data = [];
187  $warning = false;
188  $error = false;
189  $message = '';
190  $minimumRequiredMemoryLimit = '756M';
191  $recommendedForUpgradeMemoryLimit = '2G';
192 
193  $currentMemoryLimit = ini_get('memory_limit');
194 
195  $currentMemoryInteger = intval($currentMemoryLimit);
196 
197  if ($currentMemoryInteger > 0
198  && $this->dataSize->convertSizeToBytes($currentMemoryLimit)
199  < $this->dataSize->convertSizeToBytes($minimumRequiredMemoryLimit)
200  ) {
201  $error = true;
202  $message = sprintf(
203  'Your current PHP memory limit is %s.
204  Magento 2 requires it to be set to %s or more.
205  As a user with root privileges, edit your php.ini file to increase memory_limit.
206  (The command php --ini tells you where it is located.)
207  After that, restart your web server and try again.',
208  $currentMemoryLimit,
209  $minimumRequiredMemoryLimit
210  );
211  } elseif ($currentMemoryInteger > 0
212  && $this->dataSize->convertSizeToBytes($currentMemoryLimit)
213  < $this->dataSize->convertSizeToBytes($recommendedForUpgradeMemoryLimit)
214  ) {
215  $warning = true;
216  $message = sprintf(
217  'Your current PHP memory limit is %s.
218  We recommend it to be set to %s or more to use Setup Wizard.
219  As a user with root privileges, edit your php.ini file to increase memory_limit.
220  (The command php --ini tells you where it is located.)
221  After that, restart your web server and try again.',
222  $currentMemoryLimit,
223  $recommendedForUpgradeMemoryLimit
224  );
225  }
226 
227  $data['memory_limit'] = [
228  'message' => $message,
229  'error' => $error,
230  'warning' => $warning,
231  ];
232 
233  return $data;
234  }
235 
240  private function checkXDebugNestedLevel()
241  {
242  $data = [];
243  $error = false;
244 
245  $currentExtensions = $this->phpInformation->getCurrent();
246  if (in_array('xdebug', $currentExtensions)) {
247  $currentXDebugNestingLevel = intval(ini_get('xdebug.max_nesting_level'));
248  $minimumRequiredXDebugNestedLevel = $this->phpInformation->getRequiredMinimumXDebugNestedLevel();
249 
250  if ($minimumRequiredXDebugNestedLevel > $currentXDebugNestingLevel) {
251  $error = true;
252  }
253 
254  $message = sprintf(
255  'Your current setting of xdebug.max_nesting_level=%d.
256  Magento 2 requires it to be set to %d or more.
257  Edit your config, restart web server, and try again.',
258  $currentXDebugNestingLevel,
259  $minimumRequiredXDebugNestedLevel
260  );
261 
262  $data['xdebug_max_nesting_level'] = [
263  'message' => $message,
264  'error' => $error
265  ];
266  }
267 
268  return $data;
269  }
270 
280  private function checkPopulateRawPostSetting()
281  {
282  // HHVM and PHP 7does not support 'always_populate_raw_post_data' to be set to -1
283  if (version_compare(PHP_VERSION, '7.0.0-beta') >= 0 || defined('HHVM_VERSION')) {
284  return [];
285  }
286 
287  $data = [];
288  $error = false;
289  $iniSetting = intval(ini_get('always_populate_raw_post_data'));
290 
291  $checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
292  $normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
293  $currentVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
294  if ($checkVersionConstraint->matches($currentVersion) && $iniSetting !== -1) {
295  $error = true;
296  }
297 
298  $message = sprintf(
299  'Your PHP Version is %s, but always_populate_raw_post_data = %d.
300  $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
301  This will stop the installer from running.
302  Please open your php.ini file and set always_populate_raw_post_data to -1.
303  If you need more help please call your hosting provider.',
304  PHP_VERSION,
305  intval(ini_get('always_populate_raw_post_data'))
306  );
307 
308  $data['always_populate_raw_post_data'] = [
309  'message' => $message,
310  'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
311  'error' => $error
312  ];
313 
314  return $data;
315  }
316 
322  private function checkFunctionsExistence()
323  {
324  $data = [];
325  $requiredFunctions = [
326  [
327  'name' => 'imagecreatefromjpeg',
328  'message' => 'You must have installed GD library with --with-jpeg-dir=DIR option.',
329  'helpUrl' => 'http://php.net/manual/en/image.installation.php',
330  ],
331  ];
332 
333  foreach ($requiredFunctions as $function) {
334  $data['missed_function_' . $function['name']] = [
335  'message' => $function['message'],
336  'helpUrl' => $function['helpUrl'],
337  'error' => !function_exists($function['name']),
338  ];
339  }
340 
341  return $data;
342  }
343 
350  private function getNormalizedCurrentPhpVersion($version)
351  {
352  try {
353  $normalizedPhpVersion = $this->versionParser->normalize($version);
354  } catch (\UnexpectedValueException $e) {
355  $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', $version);
356  $normalizedPhpVersion = $this->versionParser->normalize($prettyVersion);
357  }
358  return $normalizedPhpVersion;
359  }
360 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$message
$settings
Definition: bootstrap.php:29
__construct(ComposerInformation $composerInformation, PhpInformation $phpInformation, VersionParser $versionParser, DataSize $dataSize)
$required
Definition: wrapper.phtml:8