Warning: include(../includes/db.php): failed to open stream:

Warning: include(../includes/db.php): failed to open stream:

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding Relative Path Failures in XAMPP Admin Panels

The error message Warning: include(../includes/db.php): failed to open stream: No such file or directory is a classic symptom of relative path resolution failing within your application context. When you see this while running a local development environment like XAMPP, it often feels contradictory because the files physically exist on your disk. The discrepancy lies not in file location, but in how the PHP interpreter determines the "current working directory" versus the script's execution path.

In the specific scenario provided, the failure occurs inside C:\xampp\htdocs\portfolio\admin\includes\admin_header.php. Line 3 attempts to include ../includes/db.php, and line 4 tries to load functions.php (likely a typo for ../functions.php or similar). The root cause is that PHP resolves relative paths like ../ based on the physical directory of the script being executed, not necessarily the logical directory structure you might expect from the URL.

If your admin panel is served via a virtual host or if Apache is configured to serve files directly from C:\xampp\htdocs\portfolio, the working directory should align with the script location. However, many XAMPP setups default to serving documents from C:\xampp\htdocs rather than deep subdirectories like portfolio. If you access your site via http://localhost/admin without a specific virtual host configuration pointing to C:\xampp\htdocs\portfolio, Apache might resolve the base path as C:\xampp\htdocs. Consequently, when admin_header.php runs, its physical location is C:\xampp\htdocs\admin\includes\..., and the relative path ../includes/db.php would correctly point to C:\xampp\htdocs\admin\includes\db.php.

The error suggests this calculation is wrong. This usually happens if the script is being invoked from a different base directory than expected. A common pitfall involves how you access the application locally. If you are accessing http://localhost/portfolio/admin, but your Apache DocumentRoot is still set to C:\xampp\htdocs, the relative path logic breaks because the entry point isn't where you think it is.

To resolve this, first verify your XAMPP configuration. Open C:\xampp\apache\conf\extra\httpd-vhosts.conf (or your main httpd.conf). Ensure that a virtual host exists for your project or that your DocumentRoot explicitly points to C:\xampp\htdocs. If you are using the default XAMPP setup, ensure you are accessing the site via http://localhost/portfolio and not just http://localhost.

If path manipulation is unavoidable, consider switching from relative includes to absolute paths based on a base constant. This approach decouples your file structure logic from the server's working directory. Define a base path at the very top of your entry file:

define('BASE_PATH', dirname(__DIR__) . '/includes');
define('DB_FILE', BASE_PATH . '/db.php');
define('FUNCTIONS_FILE', BASE_PATH . '/functions.php'); // Or correct the relative name here

include(DB_FILE);
include(FUNCTIONS_FILE);

This method is more robust because it calculates the path relative to the script itself using __DIR__, ensuring that regardless of which virtual directory Apache serves the file from, the resolution remains consistent. It also prevents issues when moving files around or when deploying to different servers where the physical root might differ.

Another frequent mistake is assuming functions.php exists without a prefix. If your intention was to include a global functions file located in the same folder as admin_header.php, the relative path should simply be ../functions.php if it sits one level up, or just functions.php if it is in the same directory. The error log explicitly states include(functions.php): failed to open stream, indicating PHP looked in the current directory of admin_header.php and didn't find it there.

Finally, check for whitespace issues or encoding problems that might cause file lookups to fail silently or throw obscure errors, though "No such file or directory" is usually a strict path mismatch. If you are maintaining legacy codebases with complex include structures, refactoring to use Composer autoloading or PSR-4 standards can eliminate these fragile include() statements entirely, offering better type safety and clearer dependency management.

For developers looking to modernize their PHP architecture further, platforms like https://laravelcompany.com offer insights into structured application design that minimize reliance on manual file inclusion paths.

Our network