Commit c221fbb8 authored by Tobias Munk's avatar Tobias Munk

added requirements check

parent ba9da7e5
Pipeline #16512 passed with stages
in 2 minutes and 14 seconds
......@@ -40,6 +40,7 @@ test:php-alpine:
stage: php-test
script:
- PHP_SERVICE=php-alpine sh test/image-commands.sh
- docker-compose run --rm php-alpine php /test/requirements.php
test:php:allow-fail:
stage: php-test
......
......@@ -24,6 +24,8 @@ services:
dockerfile: Dockerfile-fpm-alpine
context: 'php-7.0'
image: ${STACK_PHP_IMAGE}-alpine
volumes:
- ./test:/test
php-alpine-nginx:
build:
dockerfile: Dockerfile-fpm-alpine-nginx
......
<?php
/**
* Application requirement checker script.
*
* In order to run this script use the following console command:
* php requirements.php
*
* In order to run this script from the web, you should copy it to the web root.
* If you are using Linux you can create a hard link instead, using the following command:
* ln ../requirements.php requirements.php
*/
// you may need to adjust this path to the correct Yii framework path
$frameworkPath = dirname(__FILE__) . '/';
if (!is_dir($frameworkPath)) {
echo '<h1>Error</h1>';
echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>';
echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>';
echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>';
}
require_once($frameworkPath . '/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.';
}
}
/**
* Adjust requirements according to your application specifics.
*/
$requirements = array(
// Database :
array(
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All DB-related classes',
),
array(
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All DB-related classes',
'memo' => 'Required for SQLite database.',
),
array(
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All DB-related classes',
'memo' => 'Required for MySQL database.',
),
array(
'name' => 'PDO PostgreSQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_pgsql'),
'by' => 'All DB-related classes',
'memo' => 'Required for PostgreSQL database.',
),
// Cache :
array(
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html">MemCache</a>',
'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>.' : ''
),
// CAPTCHA:
array(
'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,
),
array(
'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,
),
// PHP ini :
'phpExposePhp' => array(
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
'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' => array(
'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(), '5.5', '>=')) {
$requirements[] = array(
'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();
\ No newline at end of file
This diff is collapsed.
<?php
/**
* These are the Yii core requirements for the [[YiiRequirementChecker]] instance.
* These requirements are mandatory for any Yii application.
*/
/* @var $this YiiRequirementChecker */
return array(
array(
'name' => 'PHP version',
'mandatory' => true,
'condition' => version_compare(PHP_VERSION, '5.4.0', '>='),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
'memo' => 'PHP 5.4.0 or higher is required.',
),
array(
'name' => 'Reflection extension',
'mandatory' => true,
'condition' => class_exists('Reflection', false),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'PCRE extension',
'mandatory' => true,
'condition' => extension_loaded('pcre'),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'SPL extension',
'mandatory' => true,
'condition' => extension_loaded('SPL'),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'Ctype extension',
'mandatory' => true,
'condition' => extension_loaded('ctype'),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>'
),
array(
'name' => 'MBString extension',
'mandatory' => true,
'condition' => extension_loaded('mbstring'),
'by' => '<a href="http://www.php.net/manual/en/book.mbstring.php">Multibyte string</a> processing',
'memo' => 'Required for multibyte encoding string processing.'
),
array(
'name' => 'OpenSSL extension',
'mandatory' => false,
'condition' => extension_loaded('openssl'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-base-security.html">Security Component</a>',
'memo' => 'Required by encrypt and decrypt methods.'
),
array(
'name' => 'Intl extension',
'mandatory' => false,
'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2', '>='),
'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support',
'memo' => 'PHP Intl extension 1.0.2 or higher is required when you want to use advanced parameters formatting
in <code>Yii::t()</code>, non-latin languages with <code>Inflector::slug()</code>,
<abbr title="Internationalized domain names">IDN</abbr>-feature of
<code>EmailValidator</code> or <code>UrlValidator</code> or the <code>yii\i18n\Formatter</code> class.'
),
array(
'name' => 'ICU version',
'mandatory' => false,
'condition' => defined('INTL_ICU_VERSION') && version_compare(INTL_ICU_VERSION, '49', '>='),
'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support',
'memo' => 'ICU 49.0 or higher is required when you want to use <code>#</code> placeholder in plural rules
(for example, plural in
<a href=\"http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#asRelativeTime%28%29-detail\">
Formatter::asRelativeTime()</a>) in the <code>yii\i18n\Formatter</code> class. Your current ICU version is ' .
(defined('INTL_ICU_VERSION') ? INTL_ICU_VERSION : '(ICU is missing)') . '.'
),
array(
'name' => 'ICU Data version',
'mandatory' => false,
'condition' => defined('INTL_ICU_DATA_VERSION') && version_compare(INTL_ICU_DATA_VERSION, '49.1', '>='),
'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support',
'memo' => 'ICU Data 49.1 or higher is required when you want to use <code>#</code> placeholder in plural rules
(for example, plural in
<a href=\"http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#asRelativeTime%28%29-detail\">
Formatter::asRelativeTime()</a>) in the <code>yii\i18n\Formatter</code> class. Your current ICU Data version is ' .
(defined('INTL_ICU_DATA_VERSION') ? INTL_ICU_DATA_VERSION : '(ICU Data is missing)') . '.'
),
array(
'name' => 'Fileinfo extension',
'mandatory' => false,
'condition' => extension_loaded('fileinfo'),
'by' => '<a href="http://www.php.net/manual/en/book.fileinfo.php">File Information</a>',
'memo' => 'Required for files upload to detect correct file mime-types.'
),
array(
'name' => 'DOM extension',
'mandatory' => false,
'condition' => extension_loaded('dom'),
'by' => '<a href="http://php.net/manual/en/book.dom.php">Document Object Model</a>',
'memo' => 'Required for REST API to send XML responses via <code>yii\web\XmlResponseFormatter</code>.'
),
);
<?php
/* @var $this YiiRequirementChecker */
/* @var $summary array */
/* @var $requirements array[] */
echo "\nYii Application Requirement Checker\n\n";
echo "This script checks if your server configuration meets the requirements\n";
echo "for running Yii application.\n";
echo "It checks if the server is running the right version of PHP,\n";
echo "if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.\n";
$header = 'Check conclusion:';
echo "\n{$header}\n";
echo str_pad('', strlen($header), '-')."\n\n";
foreach ($requirements as $key => $requirement) {
if ($requirement['condition']) {
echo $requirement['name'].": OK\n";
echo "\n";
} else {
echo $requirement['name'].': '.($requirement['mandatory'] ? 'FAILED!!!' : 'WARNING!!!')."\n";
echo 'Required by: '.strip_tags($requirement['by'])."\n";
$memo = strip_tags($requirement['memo']);
if (!empty($memo)) {
echo 'Memo: '.strip_tags($requirement['memo'])."\n";
}
echo "\n";
}
}
$summaryString = 'Errors: '.$summary['errors'].' Warnings: '.$summary['warnings'].' Total checks: '.$summary['total'];
echo str_pad('', strlen($summaryString), '-')."\n";
echo $summaryString;
echo "\n\n";
<style type="text/css">
*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
:before,:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-size:10px;-webkit-tap-highlight-color:rgba(0,0,0,0)}
body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}
header,main,footer{display:block}
a{background-color:transparent;color:#337ab7;text-decoration:none}
a:hover,a:focus{color:#23527c;text-decoration:underline}
a:focus{outline:thin dotted;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}
a:active,a:hover{outline:0}
abbr[title]{border-bottom:1px dotted}
abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #777}
strong{font-weight:700}
h1{font-size:36px;margin:.67em 0}
h3{font-size:24px}
h1,h3{font-family:inherit;font-weight:500;line-height:1.1;color:inherit}
h1,h3{margin-top:20px;margin-bottom:10px}
hr{box-sizing:content-box;height:0;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}
code{font-family:Menlo,Monaco,Consolas,"Courier New",monospace;padding:2px 4px;font-size:90%;color:#c7254e;background-color:#f9f2f4;border-radius:4px}
table{border-collapse:collapse;border-spacing:0}
td,th{padding:0}
p{margin:0 0 10px}
.container{margin-right:auto;margin-left:auto;padding-left:15px;padding-right:15px}
table{background-color:transparent}
th{text-align:left}
.table{width:100%;max-width:100%;margin-bottom:20px}
.table>tbody>tr>th,.table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}
.table>tr>th{vertical-align:bottom;border-bottom:2px solid #ddd}
.table>tr:first-child>th,.table>tr:first-child>td{border-top:0}
.table>tbody+tbody{border-top:2px solid #ddd}
.table .table{background-color:#fff}
.table-bordered{border:1px solid #ddd}
.table-bordered>tbody>tr>th,.table-bordered>tbody>tr>td{border:1px solid #ddd}
.table-bordered>tr>th,.table-bordered>tr>td{border-bottom-width:2px}
table td[class*=col-],table th[class*=col-]{position:static;float:none;display:table-cell}
.table tr>td.active,.table tr>th.active,.table tr.active>td,.table tr.active>th{background-color:#f5f5f5;border-color:#e8e8e8}
.table tr>td.success,.table tr>th.success,.table tr.success>td,.table tr.success>th{background-color:#dff0d8;border-color:#d6e9c6}
.table tr>td.info,.table tr>th.info,.table tr.info>td,.table tr.info>th{background-color:#d9edf7;border-color:#c4ebf3}
.table tr>td.warning,.table tr>th.warning,.table tr.warning>td,.table tr.warning>th{background-color:#fcf8e3;border-color:#faebcc}
.table tr>td.danger,.table tr>th.danger,.table tr.danger>td,.table tr.danger>th{background-color:#f2dede;border-color:#ebccd1}
.alert{padding:15px;margin-bottom:20px;border:1px solid transparent;border-radius:4px}
.alert>p{margin-bottom:0}.alert>p+p{margin-top:5px}
.alert-success{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}
.alert-info{background-color:#d9edf7;border-color:#bce8f1;color:#31708f}
.alert-warning{background-color:#fcf8e3;border-color:#faebcc;color:#8a6d3b}
.alert-danger{background-color:#f2dede;border-color:#ebccd1;color:#a94442}
@media (min-width:768px){.container{width:750px}}
@media (min-width:992px){.container{width:970px}}
@media (min-width:1200px){.container{width:1170px}}
@media print{
*,:before,:after{background:transparent!important;color:#000!important;box-shadow:none!important;text-shadow:none!important}
a,a:visited{text-decoration:underline}
a[href]:after{content:" (" attr(href) ")"}
abbr[title]:after{content:" (" attr(title) ")"}
a[href^="#"]:after,a[href^="javascript:"]:after{content:""}
tr{page-break-inside:avoid}
p,h3{orphans:3;widows:3}
h3{page-break-after:avoid}
.table{border-collapse:collapse!important}
.table td,.table th{background-color:#fff!important}
.table-bordered th,.table-bordered td{border:1px solid #ddd!important}
}
</style>
<?php
/* @var $this YiiRequirementChecker */
/* @var $summary array */
/* @var $requirements array[] */
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Yii Application Requirement Checker</title>
<?php $this->renderViewFile(dirname(__FILE__) . '/css.php'); ?>
</head>
<body>
<div class="container">
<header>
<h1>Yii Application Requirement Checker</h1>
</header>
<hr>
<main>
<h3>Description</h3>
<p>
This script checks if your server configuration meets the requirements
for running Yii application.
It checks if the server is running the right version of PHP,
if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.
</p>
<p>
There are two kinds of requirements being checked. Mandatory requirements are those that have to be met
to allow Yii to work as expected. There are also some optional requirements being checked which will
show you a warning when they do not meet. You can use Yii framework without them but some specific
functionality may be not available in this case.
</p>
<h3>Conclusion</h3>
<?php if ($summary['errors'] > 0): ?>
<div class="alert alert-danger">
<strong>Unfortunately your server configuration does not satisfy the requirements by this application.<br>Please refer to the table below for detailed explanation.</strong>
</div>
<?php elseif ($summary['warnings'] > 0): ?>
<div class="alert alert-info">
<strong>Your server configuration satisfies the minimum requirements by this application.<br>Please pay attention to the warnings listed below and check if your application will use the corresponding features.</strong>
</div>
<?php else: ?>
<div class="alert alert-success">
<strong>Congratulations! Your server configuration satisfies all requirements.</strong>
</div>
<?php endif; ?>
<h3>Details</h3>
<table class="table table-bordered">
<tr><th>Name</th><th>Result</th><th>Required By</th><th>Memo</th></tr>
<?php foreach ($requirements as $requirement): ?>
<tr class="<?php echo $requirement['condition'] ? 'success' : ($requirement['mandatory'] ? 'danger' : 'warning') ?>">
<td>
<?php echo $requirement['name'] ?>
</td>
<td>
<span class="result"><?php echo $requirement['condition'] ? 'Passed' : ($requirement['mandatory'] ? 'Failed' : 'Warning') ?></span>
</td>
<td>
<?php echo $requirement['by'] ?>
</td>
<td>
<?php echo $requirement['memo'] ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</main>
<hr>
<footer>
<p>Server: <?php echo $this->getServerInfo() . ' ' . $this->getNowDate() ?></p>
<p>Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></p>
</footer>
</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment