Config.php -
config.php is a PHP configuration file that contains settings and parameters for a web application. It is a script that defines various constants, variables, and functions that are used throughout the application to connect to databases, set up paths, and configure other essential components. The primary purpose of config.php is to provide a centralized location for storing and managing configuration data, making it easier to maintain and update the application.
// 4. Site Configuration $config['site'] = [ 'name' => 'My Awesome App', 'url' => 'https://www.myawesomeapp.com', 'timezone' => 'America/New_York' ];
WordPress is the most famous example of a config.php file, though they call it wp-config.php . It lives in the root of the installation (often inside public_html, which is a historical risk). It contains: config.php
The config.php file is much more than a dumping ground for variables. It is the boundary between your application and the hostile world, between your local machine and your production server. Treat it with the respect it deserves.
: Allowing developers to change a database password or API key in one place rather than hunting through dozens of files. config
There are two common ways to structure a PHP configuration file: : Best for global, unchangeable settings.
// 3. Application Paths (Absolute paths are safer) define('ROOT_DIR', dirname()); // Go up one level from config folder define('APP_DIR', ROOT_DIR . '/app'); define('PUBLIC_DIR', ROOT_DIR . '/public'); It contains: The config
✅ Is the file located the web root? ✅ Does it not output anything (no echo , no HTML)? ✅ Are production passwords and keys not hardcoded (using env vars instead)? ✅ Is display_errors set to 0 in production? ✅ Is there a .gitignore entry for the real config, but a tracked config.example.php ? ✅ Does every page that needs config load it via require_once ?