What are the best practices for securely storing configuration files outside of the web root in PHP applications?

To securely store configuration files outside of the web root in PHP applications, it is important to prevent direct access to these files by unauthorized users. One common approach is to place the configuration files in a directory outside of the web root and use PHP to read and parse the configuration file when needed. This ensures that the sensitive information in the configuration files is not exposed to the public.

<?php
// Define the path to the configuration file outside of the web root
$configFilePath = '/path/to/config/config.php';

// Check if the configuration file exists
if (file_exists($configFilePath)) {
    // Include the configuration file
    include $configFilePath;
    
    // Use the configuration settings as needed
    echo $config['database']['host'];
} else {
    die('Configuration file not found.');
}