Perform Self-Diagnosis Tests On Your Laravel Application
This package allows you to run self-diagnosis tests on your Laravel application. It comes with multiple checks out of the box and allows you to add custom checks yourself.
Here is an example output of the command:
storage
and bootstrap/cache
directories have the correct permissions?.env
file exist?.env.example
but not in .env
?.env
but not in .env.example
?You can install the package via composer:
composer require beyondcode/laravel-self-diagnosis
Just call the artisan command to start the checks:
php artisan self-diagnosis
You can publish the configuration file, that contains all available checks using:
php artisan vendor:publish --provider=BeyondCode\\SelfDiagnosis\\SelfDiagnosisServiceProvider
This will publish a self-diagnosis.php
file in your config
folder. This file contains all the checks that will be performed on your application.
<?php
return [
/*
* A list of environment aliases mapped to the actual environment configuration.
*/
'environment_aliases' => [
'prod' => 'production',
'live' => 'production',
'local' => 'development',
],
/*
* Common checks that will be performed on all environments.
*/
'checks' => [
\BeyondCode\SelfDiagnosis\Checks\AppKeyIsSet::class,
\BeyondCode\SelfDiagnosis\Checks\CorrectPhpVersionIsInstalled::class,
\BeyondCode\SelfDiagnosis\Checks\DatabaseCanBeAccessed::class => [
'default_connection' => true,
'connections' => [],
],
\BeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions::class => [
'directories' => [
storage_path(),
base_path('bootstrap/cache'),
],
],
\BeyondCode\SelfDiagnosis\Checks\EnvFileExists::class,
\BeyondCode\SelfDiagnosis\Checks\ExampleEnvironmentVariablesAreSet::class,
\BeyondCode\SelfDiagnosis\Checks\LocalesAreInstalled::class => [
'required_locales' => [
'en_US',
'en_US.utf8',
],
],
\BeyondCode\SelfDiagnosis\Checks\MaintenanceModeNotEnabled::class,
\BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate::class,
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled::class => [
'extensions' => [
'openssl',
'PDO',
'mbstring',
'tokenizer',
'xml',
'ctype',
'json',
],
'include_composer_extensions' => true,
],
\BeyondCode\SelfDiagnosis\Checks\StorageDirectoryIsLinked::class,
],
/*
* Environment specific checks that will only be performed for the corresponding environment.
*/
'environment_checks' => [
'development' => [
\BeyondCode\SelfDiagnosis\Checks\ComposerWithDevDependenciesIsUpToDate::class => [
'additional_options' => '--ignore-platform-reqs',
],
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsNotCached::class,
\BeyondCode\SelfDiagnosis\Checks\RoutesAreNotCached::class,
],
'production' => [
\BeyondCode\SelfDiagnosis\Checks\ComposerWithoutDevDependenciesIsUpToDate::class => [
'additional_options' => '--ignore-platform-reqs',
],
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsCached::class,
\BeyondCode\SelfDiagnosis\Checks\DebugModeIsNotEnabled::class,
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreDisabled::class => [
'extensions' => [
'xdebug',
],
],
\BeyondCode\SelfDiagnosis\Checks\RedisCanBeAccessed::class => [
'default_connection' => true,
'connections' => [],
],
\BeyondCode\SelfDiagnosis\Checks\RoutesAreCached::class,
\BeyondCode\SelfDiagnosis\Checks\ServersArePingable::class => [
'servers' => [
'www.google.com',
['host' => 'www.google.com', 'port' => 8080],
'8.8.8.8',
['host' => '8.8.8.8', 'port' => 8080, 'timeout' => 5],
],
],
\BeyondCode\SelfDiagnosis\Checks\SupervisorProgramsAreRunning::class => [
'programs' => [
'horizon',
],
'restarted_within' => 300, // max seconds since last restart, 0 to disable check
],
],
],
];
The following options are available for the individual checks:
BeyondCode\SelfDiagnosis\Checks\ComposerWithDevDependenciesIsUpToDate
'--ignore-platform-reqs'
): optional arguments for composerBeyondCode\SelfDiagnosis\Checks\ComposerWithoutDevDependenciesIsUpToDate
'--ignore-platform-reqs'
): optional arguments for composerBeyondCode\SelfDiagnosis\Checks\DatabaseCanBeAccessed
true
): if the default connection should be checked['mysql', 'sqlsrv']
, default: []
): additional connections to checkBeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions
[storage_path(), base_path('bootstrap/cache')]
, default: []
): directories to checkBeyondCode\SelfDiagnosis\Checks\LocalesAreInstalled
['en_US', 'en_US.utf8']
, default: []
): locales to checkBeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreDisabled
['xdebug', 'zlib']
, default: []
): extensions to checkBeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled
['openssl', 'PDO']
, default: []
): extensions to checkfalse
): if required extensions defined in composer.json
should be checkedBeyondCode\SelfDiagnosis\Checks\RedisCanBeAccessed
true
): if the default connection should be checked['cache_1', 'cache_2']
, default: []
): additional connections to checkBeyondCode\SelfDiagnosis\Checks\SupervisorProgramsAreRunning
['horizon', 'another-program']
, default: []
): programs that are required to be running0
= disabled), default: 0
): verifies that programs have been restarted recently to grab code updatesBeyondCode\SelfDiagnosis\Checks\ServersArePingable
['google.com', ['host' => 'google.com', 'port' => 8080]]
): servers to pingYou can create custom checks, by implementing the BeyondCode\SelfDiagnosis\Checks\Check
interface and adding the class to the config file.
Like this:
<?php
use BeyondCode\SelfDiagnosis\Checks\Check;
class MyCustomCheck implements Check
{
/**
* The name of the check.
*
* @param array $config
* @return string
*/
public function name(array $config): string
{
return 'My custom check.';
}
/**
* Perform the actual verification of this check.
*
* @param array $config
* @return bool
*/
public function check(array $config): bool
{
return true;
}
/**
* The error message to display in case the check does not pass.
*
* @param array $config
* @return string
*/
public function message(array $config): string
{
return 'This is the error message that users see if "check" returns false.';
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.