What are best practices for securely setting up database credentials in PHP configuration files?

To securely set up database credentials in PHP configuration files, it is recommended to store sensitive information such as passwords outside of the web root directory to prevent unauthorized access. One common practice is to define constants for database credentials in a separate configuration file and then include this file in your main PHP scripts. This helps to keep the credentials secure and separate from the rest of the code.

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

```php
// db_connect.php
include('config.php');

$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}