Skip to content

Instantly share code, notes, and snippets.

@hron84
Last active October 23, 2018 10:29
Show Gist options
  • Save hron84/3fc19a7d0612ba3bb650209be999ea01 to your computer and use it in GitHub Desktop.
Save hron84/3fc19a7d0612ba3bb650209be999ea01 to your computer and use it in GitHub Desktop.
<?php
function val($x) {
if($x === true) { return 'on'; }
elseif($x === false) { return 'off'; }
else { return (string)$x; }
}
function isDrupalReady() {
$result = true;
$errors = array();
$required_exts = array(
array('mysql', 'mysqli', 'pdo_mysql'),
'curl',
'gd',
'json',
'mbstring',
'openssl',
'pcre',
'pdo',
'SimpleXML',
'xml',
'xmlrpc',
);
$required_ini = array(
'mbstring.http_input' => array('pass', ''),
'magic_quotes_gpc' => array(false, NULL, ''),
'safe_mode' => array(false, NULL, ''),
'register_globals' => array(false, NULL, ''),
'session.auto_start' => 0,
'session.cache_limiter' => 'nocache',
);
foreach($required_exts as $ext) {
if(!is_array($ext)) {
if(!extension_loaded($ext)) {
$result = false;
$errors[] = "Missing PHP extension $ext";
}
} else {
$found = 0;
foreach($ext as $i) {
if(extension_loaded($i)) { $found++; }
}
if($found == 0) {
$result = false;
$errors[] = "One of the following extensions should be present: " . implode(',', $ext);
}
}
}
foreach($required_ini as $ini => $val) {
$current = ini_get($ini);
if(!is_array($val)) {
if(is_numeric($val)) {
if($current < $val) {
$result = false;
$errors[] = sprintf("Drupal.org recommends %s to set minimum %s", $ini, $val);
}
} else {
if($current !== $val) {
$result = false;
$errors[] = sprintf("Drupal.org recommends %s to set %s value", $ini, val($val));
}
}
} else {
if(!in_array($current, $val)) {
$result = false;
$errors[] = sprintf("Drupal.org recommends %s to be set one of these values: %s", $ini, join(', ', $val));
}
}
}
return array('result' => $result, 'errors' => $errors);
}
$readiness = isDrupalReady();
$php_version = phpversion();
if($readiness['result'] == true) {
echo "Your PHP {$php_version} installation is Drupal-ready!" . PHP_EOL;
} else {
echo "Your PHP {$php_version} installation does not follow Drupal.org recommendations, please fix following problems:" . PHP_EOL;
foreach($readiness['errors'] as $error) {
echo " >> {$error}" . PHP_EOL;
}
}
@hron84
Copy link
Author

hron84 commented Oct 23, 2018

TODO:

  • Add PHP version check
  • Refine for Drupal-version specific checks (e.g. D6 does not run correctly above PHP 5.6, but potentially requires ereg extension)
  • Support wider database engine checks
  • ImageMagick?
  • Support XDebug if installed
  • Check APC if applicable
  • Support error_reporting leveling (for prod and dev)
  • Support ini checks false-off-0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment