In PHP file storage, how do I handle configuration and secrets?

Configuration Management, Secrets Handling, PHP File Storage
This guide explains how to handle configuration and secrets securely when storing them in PHP files.

    // Configuration file (config.php)
    return [
        'db_host' => 'localhost',
        'db_user' => 'root',
        'db_password' => 'your_secure_password',
        'db_name' => 'database_name',
        'api_key' => getenv('API_KEY') // Loading sensitive information from environment variables
    ];

    // Usage of the configuration
    $config = require 'config.php';
    $mysqli = new mysqli($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);

    if ($mysqli->connect_error) {
        die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    }
    // Use the API key securely
    echo 'Your API key is: ' . $config['api_key'];
    

Configuration Management Secrets Handling PHP File Storage