tl;dr: How do I make PHP interpret relative paths in include/require statement from the perspective of the current file?
This is yet another question about that old issue in PHP about relative paths. Please bear with me, as I couldn't find any solution for what I am specifically trying to do.
Consider the following directory tree and files:
[www]:
index.php
config.php
[webroot]:
home.php
index.php
requires home.php
, found inside webroot
:
require('webroot/home.php');
home.php
requires config.php
, found in the parent directory:
require('../config.php');
My problem is that this won't work in my local development environment (Ubuntu 14.04 LTS / 15.10), whereas it runs flawlessly in production. Every mentioned environment is running Apache 2 and PHP 5.
Strangely, this does run locally when I run it inside my Vagrant VM (Ubuntu 12.04 LTS), accessing it from the host machine. But, right now, I cannot run a VM here.
So, why do these environments behave so differently?
This makes me believe that there must be a way to change how PHP interprets relative paths. I am currently working with a 6GB+ PHP project that is written like the example above, and I really need to avoid the amount of effort that it'll take from me to rewrite every include/require statement (using dirname(__FILE__)
or so), as well as the git merge conflicts this might cause.
EDIT: I've just remembered I actually had already asked this question here: PHP: include inside included file
.git
folder. And even then, I doubt that there's that much actual code, there's presumably some images and stuff in there. The entire Linux kernel is only ~600MB unzipped (in 52 thousand files). Nonetheless, I've answered your question as posed.find path/to/project -type f -name '*.php' -print0 | du -ch --files0-from=-
; or more relevantly, how many PHP files there are:find path/to/project -type f -name '*.php' | wc -l
)