forked from opensourcewebsite-org/opensourcewebsite-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequirements.php
More file actions
155 lines (139 loc) · 4.65 KB
/
requirements.php
File metadata and controls
155 lines (139 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Application requirement checker script.
*
* In order to run this script use the following console command:
* php requirements.php
*/
ini_set('display_errors', 1);
error_reporting(E_ALL);
use Dotenv\Dotenv;
require __DIR__ . '/vendor/autoload.php';
if (file_exists('.env')) {
$dotenv = new Dotenv(__DIR__);
$dotenv->load();
} elseif (file_exists('.env.test')) {
$dotenv = new Dotenv(__DIR__, '.env.test');
$dotenv->load();
} else {
exit;
}
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV') ?: 'requirements');
if (YII_ENV != 'dev') {
exit;
}
require_once __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
require_once __DIR__ . '/vendor/yiisoft/yii2/requirements/YiiRequirementChecker.php';
$requirementsChecker = new YiiRequirementChecker();
$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
$gdOK = $imagickOK = false;
if (extension_loaded('imagick')) {
$imagick = new Imagick();
$imagickFormats = $imagick->queryFormats('PNG');
if (in_array('PNG', $imagickFormats)) {
$imagickOK = true;
} else {
$imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
}
}
if (extension_loaded('gd')) {
$gdInfo = gd_info();
if (!empty($gdInfo['FreeType Support'])) {
$gdOK = true;
} else {
$gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
}
}
$connection = new \yii\db\Connection([
'dsn' => 'mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
]);
switch ($connection->driverName) {
case 'mysql':
$dbVersionOk = version_compare($connection->getServerVersion(), '8.0.0', '>=') ? true : false;
break;
default:
$dbVersionOk = false;
break;
}
/**
* Adjust requirements according to your application specifics.
*/
$requirements = [
// Database :
[
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All DB-related classes',
],
[
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => '<a href="https://www.php.net/manual/en/ref.pdo-mysql.php">PDO MySQL extension</a>',
'memo' => 'Required for MySQL database.',
],
[
'name' => 'MySQL server version',
'mandatory' => true,
'condition' => $dbVersionOk,
'by' => 'Checking DB version',
'memo' => 'MySQL checking database version',
],
// CAPTCHA:
[
'name' => 'GD PHP extension with FreeType support',
'mandatory' => false,
'condition' => $gdOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $gdMemo,
],
[
'name' => 'ImageMagick PHP extension with PNG support',
'mandatory' => false,
'condition' => $imagickOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $imagickMemo,
],
// JSON
[
'name' => 'JSON extension',
'mandatory' => true,
'condition' => extension_loaded('json'),
'by' => '<a href="https://www.php.net/manual/en/book.json.php">JSON extension</a>'
],
// PHP ini :
'phpExposePhp' => [
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
],
'phpAllowUrlInclude' => [
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
],
'phpSmtp' => [
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP')) > 0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
],
];
// OPcache check
if (!version_compare(phpversion(), '7.4', '>=')) {
$requirements[] = [
'name' => 'APC extension',
'mandatory' => false,
'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
];
}
$requirementsChecker->checkYii()->check($requirements)->render();