-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathsetup_extensions.php
More file actions
executable file
·75 lines (62 loc) · 2.48 KB
/
setup_extensions.php
File metadata and controls
executable file
·75 lines (62 loc) · 2.48 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
#!/usr/bin/php
<?php
/**
* A very simple script in charge of generating the PHP configuration based on environment variables.
* The script is run on each start of the container.
*/
require __DIR__.'/utils.php';
//$compiledExtensions = [
// 'ftp', 'mysqlnd', 'mbstring'
//];
$availableExtensions = getAvailableExtensions();
$phpExtensions = getPhpExtensionsEnvVar();
$phpVersion = getPhpVersionEnvVar();
//foreach ($compiledExtensions as $phpExtension) {
// $envName = 'PHP_EXTENSION_'.strtoupper($phpExtension);
//
// $env = strtolower(trim(getenv($envName)));
//
// if ($env === '0' || $env === 'false' || $env === 'no' || $env === 'off') {
// file_put_contents('php://stderr', "You cannot disable extension '$phpExtension'. It is compiled in the PHP binary.\n");
// exit(1);
// }
// if (enableExtension($phpExtension)) {
// file_put_contents('php://stderr', "You cannot explicitly enable extension '$phpExtension'. It is compiled in the PHP binary and therefore always available.\n");
// exit(1);
// }
//}
// Validate the content of PHP_EXTENSIONS
foreach ($phpExtensions as $phpExtension) {
if (!in_array($phpExtension, $availableExtensions, true)) {
file_put_contents('php://stderr', "Invalid extension name found in PHP_EXTENSIONS environment variable. Found: '$phpExtension'. Available extensions: ".implode(', ', $availableExtensions).".\n");
exit(1);
}
}
if (enableExtension('xdebug') && enableExtension('blackfire')) {
error_log('WARNING: Both Blackfire and Xdebug are enabled. This is not recommended as the PHP engine may not behave as expected. You should strongly consider disabling Xdebug or Blackfire.');
}
$toDisable = [];
$toEnable = [];
foreach ($availableExtensions as $extension) {
if (enableExtension($extension)) {
$toEnable[$extension] = $extension;
} else {
$toDisable[$extension] = $extension;
}
}
// mysqlnd is a dependency required for mysqli or pdo_mysql
if (enableExtension('mysqli') || enableExtension('pdo_mysql')) {
$toEnable['mysqlnd'] = 'mysqlnd';
unset($toDisable['mysqlnd']);
}
// curl is a dependency required for blackfire 8 (see https://blog.blackfire.io/php-8-support.html)
/*if (enableExtension('blackfire')) {
$toEnable['curl'] = 'curl';
unset($toDisable['curl']);
}*/
if ($toDisable) {
echo 'phpdismod -v ' . $phpVersion . ' ' . implode(' ', $toDisable)."\n";
}
if ($toEnable) {
echo 'phpenmod -v ' . $phpVersion . ' ' . implode(' ', $toEnable)."\n";
}