In what ways can PHP scripts be structured to allow for secure retrieval of sensitive data during installation routines?

When retrieving sensitive data during installation routines in PHP scripts, it is crucial to ensure that the data is securely handled to prevent unauthorized access. One way to achieve this is by storing sensitive data, such as database credentials or API keys, in a separate configuration file outside of the web root directory. This prevents direct access to the file via a URL and reduces the risk of exposure.

// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');

// installation_script.php
include_once('../config.php');

// Use the sensitive data securely in the installation routine
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}