How can developers ensure secure access to sensitive information in configuration files in PHP projects?

Developers can ensure secure access to sensitive information in configuration files in PHP projects by storing the sensitive information outside of the web root directory, using environment variables to access the information, and restricting file permissions on the configuration files.

// Example of accessing sensitive information from environment variables in PHP

$db_host = getenv('DB_HOST');
$db_username = getenv('DB_USERNAME');
$db_password = getenv('DB_PASSWORD');
$db_name = getenv('DB_NAME');

// Use the retrieved variables to establish a database connection
$conn = new mysqli($db_host, $db_username, $db_password, $db_name);