Apache .htaccess :
: Ideally, store config.php in a folder above the public web root (e.g., in an includes/ folder) to prevent it from being accidentally accessed via a browser. config.php
├── html/ <- Invisible to the web browser │ └── config.php <- Safe location └── html_public/ <- Accessible to the public └── index.php <- Includes config via: require '../html/config.php'; Apache
Professional config files include security "features" to protect the server: Disable PHP Directives: Apache .htaccess : : Ideally
If you have a team of developers, or if your local development environment differs from your live production server, you can dynamically adjust your config logic.
<?php // config.php $config['db']['pass'] = getenv('DB_PASSWORD') ?: 'default_dev_pass'; $config['stripe_key'] = getenv('STRIPE_SECRET_KEY');
public static $database = [ 'host' => 'localhost', 'name' => 'my_db', ];