Skip to content

Commit

Permalink
Merge branch 'main' into 2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/requirements/requirements.php
  • Loading branch information
brandonkelly committed Nov 6, 2021
2 parents a080638 + d787e1b commit 2ba43a8
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @angrybrad @brandonkelly
32 changes: 32 additions & 0 deletions .github/workflows/generate-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Generate Release
on:
push:
tags:
- "*.*.*"

jobs:
generate_release:
name: Generate release
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Archive release
uses: thedoctor0/zip-release@master
with:
type: tar
directory: ./server
filename: ../craftcms-server-check.tar.gz
exclusions: '*.git*'

- name: Generate SHA256
run: sha256sum -b craftcms-server-check.tar.gz > sha256sum.txt

- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
sha256sum.txt
craftcms-server-check.tar.gz
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog for Craft CMS Server Check

## 1.2.1 - 2021-05-25

### Added
- Added a check for MySQL to see if the server has been configured with full timezone support.

## 1.2.0 2020-11-04

### Changed
- Bumped the PHP requirement to 7.2.5 for Craft 3.6.0.

## 1.1.9 - 2020-05-28

### Added
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,36 @@

This script checks if a web server meets the minimum requirements to run a Craft 3 installation.

You can upload the `server` folder to your web server's public html folder and load `checkit.php` from your browser
## Usage

Run the following in a terminal of any [\*nix](https://en.wikipedia.org/wiki/Unix-like) environment (e.g. Linux, MacOS, WSL).

```bash
curl -Lsf https://raw.githubusercontent.com/craftcms/server-check/HEAD/check.sh | bash
```

Alternatively, you can upload the `server` folder to your web server's public html folder and load `checkit.php` from your browser
or upload `server` anywhere on your server and execute `php checkit.php` from the console to see the results.

## Shell exit codes

If all requirements are met, the script will return an exit code of `0`.

The script will return an exit code of `1` if:

- Any errors are encountered, or requirements are not met
- An environment variable `CRAFT_STRICT_SERVER_CHECK=1` is set, and any _warnings_ are found:

```bash
CRAFT_STRICT_SERVER_CHECK=1 php server/checkit.php
```

This can be espically useful in a CI/CD pipeline, or a `Dockerfile`, where you want the process to fail if the check does not pass:

```Dockerfile
# Dockerfile
FROM php:8.0-fpm
RUN curl -Lsf https://raw.githubusercontent.com/craftcms/server-check/HEAD/check.sh | bash
```

The official [Craft Docker Images](https://github.com/craftcms/docker) run this check when building to be certain all of Craft's requirements are met in any built image.
50 changes: 50 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Craft CMS Server Check (one-liner)
#
# From the environment you want to check, run:
# `curl -Lsf https://raw.githubusercontent.com/craftcms/server-check/HEAD/check.sh | bash`

[[ $- = *i* ]] && echo "Don't source this script!" && return 10

checkTools() {
Tools=("curl" "php" "rm" "tar" "grep" "cut")

for tool in ${Tools[*]}; do
if ! checkCmd $tool; then
echo "Aborted, missing $tool."
exit 6
fi
done
}

checkCmd() {
command -v "$1" > /dev/null 2>&1
}

function serverCheck() {
checkTools

tmpDir="/tmp/craftcms-server-check"
assetUrl="https://github.com/craftcms/server-check/releases/latest/download/craftcms-server-check.tar.gz"
downloadToFile="${tmpDir}/craftcms-server-check.tar.gz"
phpScript="${tmpDir}/checkit.php"

echo "Downloading file… ${assetUrl}"
mkdir "${tmpDir}"
curl -fsSL "${assetUrl}" --output "${downloadToFile}"

echo "Extracting…"
tar -xzf "${downloadToFile}" -C "${tmpDir}"

echo "Running Craft Server Check…"
php $phpScript
returnCode=$?

rm -rf "${tmpDir}"

return $returnCode
}

serverCheck
exit $?
7 changes: 7 additions & 0 deletions server/checkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@

$checker = new RequirementsChecker();
$checker->checkCraft()->render();
$strict = (bool) getenv('CRAFT_STRICT_SERVER_CHECK');

if ($checker->result['summary']['errors'] || ($strict && $checker->result['summary']['warnings'])) {
exit(1);
}

exit(0);
21 changes: 21 additions & 0 deletions server/requirements/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,27 @@ function isInnoDbSupported($conn)
return false;
}

/**
* This method attempts to see if MySQL timezone data has been populated on
* the MySQL server Craft is configured to use.
*
* https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html
*
* @param PDO $conn
* @return bool
*/
function validateDatabaseTimezoneSupport($conn)
{
$query = $conn->query("SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central') AS time1");
$result = $query->fetchColumn();

if (!$result) {
return false;
}

return true;
}

/**
* @return array
*/
Expand Down
10 changes: 8 additions & 2 deletions server/requirements/requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'name' => 'PDO MySQL extension',
'mandatory' => true,
'condition' => extension_loaded('pdo_mysql'),
'memo' => 'The <https://php.net/manual/en/ref.pdo-mysql.php>PDO MySQL</a> extension is required.'
'memo' => 'The <a rel="noopener" target="_blank" href="https://php.net/manual/en/ref.pdo-mysql.php">PDO MySQL</a> extension is required.'
);
if ($conn !== false) {
$requirements[] = array(
Expand All @@ -36,14 +36,20 @@
'condition' => $this->isInnoDbSupported($conn),
'memo' => 'Craft CMS requires the MySQL InnoDB storage engine to run.',
);
$requirements[] = array(
'name' => 'MySQL timezone support',
'mandatory' => false,
'condition' => $this->validateDatabaseTimezoneSupport($conn),
'memo' => 'MySQL should be configured with <a rel="noopener" target="_blank" href="https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html">full timezone support</a>.',
);
}
break;
case 'pgsql':
$requirements[] = array(
'name' => 'PDO PostgreSQL extension',
'mandatory' => true,
'condition' => extension_loaded('pdo_pgsql'),
'memo' => 'The <https://php.net/manual/en/ref.pdo-pgsql.php>PDO PostgreSQL</a> extension is required.'
'memo' => 'The <a rel="noopener" target="_blank" href="https://php.net/manual/en/ref.pdo-pgsql.php">PDO PostgreSQL</a> extension is required.'
);
if ($conn !== false) {
$requirements[] = array(
Expand Down
110 changes: 55 additions & 55 deletions server/views/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Craft CMS Requirement Checker</title>
<?php $this->renderViewFile(__DIR__.'/css.php'); ?>
<meta charset="utf-8"/>
<title>Craft CMS Requirement Checker</title>
<?php $this->renderViewFile(__DIR__.'/css.php'); ?>
</head>
<body>
<div class="container">
<div class="header">
<h1>Craft CMS Requirement Checker</h1>
</div>
<hr>
<div class="header">
<h1>Craft CMS Requirement Checker</h1>
</div>
<hr>

<div class="content">
<h3>Description</h3>
<p>
This script checks if your web server configuration meets the requirements for running a Craft CMS installation.
<div class="content">
<h3>Description</h3>
<p>
This script checks if your web server configuration meets the requirements for running a Craft CMS installation.
It checks if the server is running the right version of PHP, if appropriate PHP extensions have been loaded, and if <code>php.ini</code> 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 Craft 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 Craft without them but some specific
functionality may be not available in this case.
</p>
</p>
<p>
There are two kinds of requirements being checked. Mandatory requirements are those that have to be met
to allow Craft 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 Craft without them but some specific
functionality may be not available in this case.
</p>

<h3>Results</h3>
<?php if ($summary['errors'] > 0): ?>
<div class="alert alert-danger">
<strong>Unfortunately your server configuration does not meet the requirements to run Craft.<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 meet the minimum requirements to run Craft.<br>Please pay attention to the warnings listed below and check if your site will use the corresponding features.</strong>
</div>
<?php else: ?>
<div class="alert alert-success">
<strong>Congratulations! Your server configuration can run Craft!</strong>
</div>
<?php endif; ?>
<h3>Results</h3>
<?php if ($summary['errors'] > 0): ?>
<div class="alert alert-danger">
<strong>Unfortunately your server configuration does not meet the requirements to run Craft.<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 meet the minimum requirements to run Craft.<br>Please pay attention to the warnings listed below and check if your site will use the corresponding features.</strong>
</div>
<?php else: ?>
<div class="alert alert-success">
<strong>Congratulations! Your server configuration can run Craft!</strong>
</div>
<?php endif; ?>

<h3>Details</h3>
<h3>Details</h3>

<table class="table table-bordered">
<tr><th>Name</th><th>Result</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['memo'] ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<table class="table table-bordered">
<tr><th>Name</th><th>Result</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['memo'] ?>
</td>
</tr>
<?php endforeach; ?>
</table>

</div>
</div>

<hr>
<hr>

<div class="footer">
<p>Server: <?php echo $this->getServerInfo().' '.$this->getCurrentDate() ?></p>
<p>Powered by <a href="https://craftcms.com/" rel="external">Craft</a></p>
</div>
<div class="footer">
<p>Server: <?php echo $this->getServerInfo().' '.$this->getCurrentDate() ?></p>
<p>Powered by <a href="https://craftcms.com/" rel="external">Craft</a></p>
</div>
</div>
</body>
</html>

0 comments on commit 2ba43a8

Please sign in to comment.