-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from andrewnicols/phpini
Add simple environment-based PHP configuration
- Loading branch information
Showing
5 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
echo "Checking for php configuration in environment" | ||
|
||
localinifile="/usr/local/etc/php/conf.d/10-local.ini" | ||
|
||
cat <<'EOF' > $localinifile | ||
; -- | ||
; Automatically generated php ini configuration for Moodle | ||
; -- | ||
EOF | ||
|
||
env | while IFS= read -r line; do | ||
value=${line#*=} | ||
fullname=${line%%=*} | ||
if [[ $fullname = PHP_INI-* ]]; then | ||
name=`echo $fullname | sed 's/^PHP_INI-//'` | ||
echo "=> Found '${name}' with value '${value}'" | ||
|
||
cat << EOF >> $localinifile | ||
; $fullname=$value | ||
$name = $value | ||
EOF | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
<?php | ||
|
||
$uploadsEnabled = ini_get('file_uploads'); | ||
$fileuploads = ini_get('file_uploads'); | ||
$apcenabled = ini_get('apc.enabled'); | ||
$memorylimit = ini_get('memory_limit'); | ||
|
||
$allokay = true; | ||
$message = []; | ||
if (!empty($fileuploads)) { | ||
$allokay = false; | ||
$message[] = "Uploads are enabled and should be disabled."; | ||
$message[] = var_export($fileuploads, true); | ||
} | ||
|
||
if (!empty($apcenabled)) { | ||
$allokay = false; | ||
$message[] = "apc.enabled is not Off (0): ({$apcenabled})"; | ||
} | ||
|
||
if ($memorylimit !== '256M') { | ||
$allokay = false; | ||
$message[] = "Memory limit not set to 256M: ({$memorylimit})"; | ||
} | ||
|
||
if (php_sapi_name() === 'cli') { | ||
if (empty($uploadsEnabled)) { | ||
if ($allokay) { | ||
echo "OK\n"; | ||
exit(0); | ||
} | ||
echo "Uploads are enabled and should be disabled."; | ||
var_dump($uploadsEnabled); | ||
|
||
echo implode("\n", $message) . "\n"; | ||
exit(1); | ||
} else { | ||
if (empty($uploadsEnabled)) { | ||
if ($allokay) { | ||
header('HTTP/1.1 200 - OK'); | ||
exit(0); | ||
} | ||
header('HTTP/1.1 500 - Uploads are enabled and should be disabled: ' . var_export($uploadsEnabled, true)); | ||
|
||
header('HTTP/1.1 500 - ' . implode(", ", $message)); | ||
echo implode("<br>", $message); | ||
exit(1); | ||
} |