requirements.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * Application requirement checker script.
  4. *
  5. * In order to run this script use the following console command:
  6. * php requirements.php
  7. *
  8. * In order to run this script from the web, you should copy it to the web root.
  9. * If you are using Linux you can create a hard link instead, using the following command:
  10. * ln ../requirements.php requirements.php
  11. */
  12. // you may need to adjust this path to the correct Yii framework path
  13. // uncomment and adjust the following line if Yii is not located at the default path
  14. //$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
  15. if (!isset($frameworkPath)) {
  16. $searchPaths = array(
  17. dirname(__FILE__) . '/vendor/yiisoft/yii2',
  18. dirname(__FILE__) . '/../vendor/yiisoft/yii2',
  19. );
  20. foreach ($searchPaths as $path) {
  21. if (is_dir($path)) {
  22. $frameworkPath = $path;
  23. break;
  24. }
  25. }
  26. }
  27. if (!isset($frameworkPath) || !is_dir($frameworkPath)) {
  28. $message = "<h1>Error</h1>\n\n"
  29. . "<p><strong>The path to yii framework seems to be incorrect.</strong></p>\n"
  30. . '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . "</abbr>.</p>\n"
  31. . '<p>Please refer to the <abbr title="' . dirname(__FILE__) . "/README.md\">README</abbr> on how to install Yii.</p>\n";
  32. if (!empty($_SERVER['argv'])) {
  33. // do not print HTML when used in console mode
  34. echo strip_tags($message);
  35. } else {
  36. echo $message;
  37. }
  38. exit(1);
  39. }
  40. require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
  41. $requirementsChecker = new YiiRequirementChecker();
  42. $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
  43. $gdOK = $imagickOK = false;
  44. if (extension_loaded('imagick')) {
  45. $imagick = new Imagick();
  46. $imagickFormats = $imagick->queryFormats('PNG');
  47. if (in_array('PNG', $imagickFormats)) {
  48. $imagickOK = true;
  49. } else {
  50. $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
  51. }
  52. }
  53. if (extension_loaded('gd')) {
  54. $gdInfo = gd_info();
  55. if (!empty($gdInfo['FreeType Support'])) {
  56. $gdOK = true;
  57. } else {
  58. $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
  59. }
  60. }
  61. /**
  62. * Adjust requirements according to your application specifics.
  63. */
  64. $requirements = array(
  65. // Database :
  66. array(
  67. 'name' => 'PDO extension',
  68. 'mandatory' => true,
  69. 'condition' => extension_loaded('pdo'),
  70. 'by' => 'All DB-related classes',
  71. ),
  72. array(
  73. 'name' => 'PDO SQLite extension',
  74. 'mandatory' => false,
  75. 'condition' => extension_loaded('pdo_sqlite'),
  76. 'by' => 'All DB-related classes',
  77. 'memo' => 'Required for SQLite database.',
  78. ),
  79. array(
  80. 'name' => 'PDO MySQL extension',
  81. 'mandatory' => false,
  82. 'condition' => extension_loaded('pdo_mysql'),
  83. 'by' => 'All DB-related classes',
  84. 'memo' => 'Required for MySQL database.',
  85. ),
  86. array(
  87. 'name' => 'PDO PostgreSQL extension',
  88. 'mandatory' => false,
  89. 'condition' => extension_loaded('pdo_pgsql'),
  90. 'by' => 'All DB-related classes',
  91. 'memo' => 'Required for PostgreSQL database.',
  92. ),
  93. // Cache :
  94. array(
  95. 'name' => 'Memcache extension',
  96. 'mandatory' => false,
  97. 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
  98. 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html">MemCache</a>',
  99. 'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html#$useMemcached-detail">MemCache::useMemcached</a> to <code>true</code>.' : ''
  100. ),
  101. // CAPTCHA:
  102. array(
  103. 'name' => 'GD PHP extension with FreeType support',
  104. 'mandatory' => false,
  105. 'condition' => $gdOK,
  106. 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
  107. 'memo' => $gdMemo,
  108. ),
  109. array(
  110. 'name' => 'ImageMagick PHP extension with PNG support',
  111. 'mandatory' => false,
  112. 'condition' => $imagickOK,
  113. 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
  114. 'memo' => $imagickMemo,
  115. ),
  116. // PHP ini :
  117. 'phpExposePhp' => array(
  118. 'name' => 'Expose PHP',
  119. 'mandatory' => false,
  120. 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
  121. 'by' => 'Security reasons',
  122. 'memo' => '"expose_php" should be disabled at php.ini',
  123. ),
  124. 'phpAllowUrlInclude' => array(
  125. 'name' => 'PHP allow url include',
  126. 'mandatory' => false,
  127. 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
  128. 'by' => 'Security reasons',
  129. 'memo' => '"allow_url_include" should be disabled at php.ini',
  130. ),
  131. 'phpSmtp' => array(
  132. 'name' => 'PHP mail SMTP',
  133. 'mandatory' => false,
  134. 'condition' => strlen(ini_get('SMTP')) > 0,
  135. 'by' => 'Email sending',
  136. 'memo' => 'PHP mail SMTP server required',
  137. ),
  138. );
  139. // OPcache check
  140. if (!version_compare(phpversion(), '5.5', '>=')) {
  141. $requirements[] = array(
  142. 'name' => 'APC extension',
  143. 'mandatory' => false,
  144. 'condition' => extension_loaded('apc'),
  145. 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
  146. );
  147. }
  148. $result = $requirementsChecker->checkYii()->check($requirements)->getResult();
  149. $requirementsChecker->render();
  150. exit($result['summary']['errors'] === 0 ? 0 : 1);