定制 ferasshita/env-health 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ferasshita/env-health

Composer 安装命令:

composer require ferasshita/env-health

包简介

A PHP CLI security auditor that scans project environment and returns a Security Health Score

README 文档

README

A PHP 8.3+ CLI security auditor that scans your project environment and returns a comprehensive Security Health Score based on common vulnerabilities.

Features

  • 🔍 Comprehensive Security Audits: Four specialized auditors to check different aspects of your project's security
  • 📊 Health Score: Get an overall security score out of 100 with color-coded feedback
  • 🎨 Beautiful CLI Output: Uses Symfony Console with tables and colors for easy-to-read results
  • Fully Tested: Complete PHPUnit test suite with mocked file permissions
  • 🔌 Extensible: Easy to add custom auditors using the AuditorInterface

Installation

Via Composer

composer require ferasshita/env-health

From Source

git clone https://github.com/ferasshita/ENV-Health.git
cd ENV-Health
composer install

Usage

Run the security audit in your project directory:

./vendor/bin/env-health

Or specify a custom path:

./vendor/bin/env-health --path=/path/to/project

Security Auditors

1. DotEnv Auditor

Checks if .env file exists and verifies its permissions.

Checks:

  • File existence
  • Permissions should be 0600 or 0640
  • Not globally readable

Score:

  • PASS (100): Secure permissions (0600 or 0640)
  • ⚠️ WARN (80): No .env file found
  • ⚠️ WARN (50): Non-optimal permissions
  • FAIL (0): Globally readable

2. Private Key Auditor

Scans the project for .pem or .key files and validates their security.

Checks:

  • Finds all private key files in the project
  • Ensures keys are not in public directories (e.g., /public)
  • Verifies permissions are set to 0600

Score:

  • PASS (100): No keys found OR all keys are secure
  • FAIL (0): Keys in public directory OR wrong permissions

3. PHP Configuration Auditor

Checks PHP configuration settings for production readiness.

Checks:

  • display_errors should be OFF
  • allow_url_fopen is flagged as a potential risk

Score:

  • PASS (100): All settings secure
  • ⚠️ WARN (70): allow_url_fopen enabled
  • FAIL (30): display_errors enabled

4. Auth Method Auditor

Evaluates database authentication methods.

Checks:

  • Looks for DB_SSL_KEY in environment (preferred)
  • Checks for DB_PASSWORD (less secure)

Score:

  • PASS (100): Using SSL keys for authentication
  • ⚠️ WARN (80): No database authentication configured
  • ⚠️ WARN (60): Using password authentication

Output Example

ENV-Health Security Audit
=========================

+--------------------------------------+--------+------------------------------------------------------------------------------------+
| Check Name                           | Status | Suggestion                                                                         |
+--------------------------------------+--------+------------------------------------------------------------------------------------+
| DotEnv Security Check                | ✓ PASS | .env file has secure permissions.                                                  |
| Private Key Security Check           | ✓ PASS | No private key files found in project.                                             |
| PHP Configuration Check              | ⚠ WARN | Warnings: allow_url_fopen is ON (potential security risk)                          |
| Database Authentication Method Check | ✓ PASS | Using SSL keys for database authentication. Excellent security practice!           |
+--------------------------------------+--------+------------------------------------------------------------------------------------+


 [OK] ══════════════════════════════════
        SECURITY HEALTH SCORE: 93/100
      ══════════════════════════════════
        Status: EXCELLENT ✓

Color-Coded Health Scores

  • 🟢 80-100: EXCELLENT ✓ (Green)
  • 🟡 50-79: NEEDS IMPROVEMENT ⚠ (Yellow)
  • 🔴 0-49: CRITICAL ✗ (Red)

Development

Running Tests

composer test
# or
./vendor/bin/phpunit

Project Structure

ENV-Health/
├── bin/
│   └── env-health          # CLI executable
├── src/
│   ├── Contract/
│   │   ├── AuditorInterface.php
│   │   └── AuditResult.php
│   ├── Auditor/
│   │   ├── DotEnvAuditor.php
│   │   ├── PrivateKeyAuditor.php
│   │   ├── PhpIniAuditor.php
│   │   └── AuthMethodAuditor.php
│   ├── Command/
│   │   └── AuditCommand.php
│   └── AuditRunner.php
├── tests/
│   ├── Auditor/
│   └── AuditRunnerTest.php
└── composer.json

Creating Custom Auditors

You can easily create your own auditors by implementing the AuditorInterface:

<?php

namespace YourNamespace;

use EnvHealth\Contract\AuditorInterface;
use EnvHealth\Contract\AuditResult;

class CustomAuditor implements AuditorInterface
{
    public function getName(): string
    {
        return 'Custom Security Check';
    }

    public function audit(): AuditResult
    {
        // Your audit logic here
        $isSecure = true; // Your check

        if ($isSecure) {
            return new AuditResult(
                $this->getName(),
                AuditResult::STATUS_PASS,
                100,
                'Everything is secure!'
            );
        }

        return new AuditResult(
            $this->getName(),
            AuditResult::STATUS_FAIL,
            0,
            'Security issue found!'
        );
    }
}

Then add it to the runner in your custom command or script.

Requirements

  • PHP 8.3 or higher
  • Symfony Console ^7.0
  • Composer

Tech Stack

  • PHP 8.3+: Modern PHP with strict types
  • Symfony Console: For beautiful CLI output
  • PHPUnit 11: For comprehensive testing
  • PSR-4 Autoloading: For organized code structure

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open-sourced under the MIT License. See the LICENSE file for details.

Security

If you discover any security issues, please email the maintainers instead of using the issue tracker.

Credits

Created by Feras Shita

⭐ Star this repository if you find it helpful!

ferasshita/env-health 适用场景与选型建议

ferasshita/env-health 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ferasshita/env-health 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ferasshita/env-health 我们能提供哪些服务?
定制开发 / 二次开发

基于 ferasshita/env-health 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08