Ok, I made a test:
I created a file called index.php that contains this line <? include("test.inc"); ?>.
Then I created a file called test.inc that contains the word "test".
I put both files in the /Sites/ folder and accessed the folder by typing http://localhost/~myusername in the browser
Everything works nice. I see the word test.
Then I opened the file index.php and modified the line into: <? include($DOCUMENT_ROOT."test.inc"); ?>. I opened the browser and pointed it to http://localhost/~myusername/
Everything works nice. I see the word test again.
So, then I created a folder called test and inside that folder I put the modified file called index.php and left the file test.inc where it is, so now I have this directory structure:
/Sites/test.inc
/Sites/test/index.php
Now if I point the browser to http://localhost/~myusername/ I get these errors:
Warning: main(test.inc): failed to open stream: No such file or directory in /Users/memoryman/Sites/test/index.php on line 1
Warning: main(): Failed opening 'test.inc' for inclusion (include_path='.:/usr/lib/php') in /Users/memoryman/Sites/test/index.php on line 1
So my conclusion is, somehow in Mac every folder is considered the root folder so $DOCUMENT_ROOT always refers to the folder where the file is launched from, which is not a normal behaviour, considering that for years on a server if the root was:
/
and a file was in:
/folder/
I could include a file inside the root using include($DOCUMENT_ROOT."filename.inc");
How can I address this issue so that I can work locally as if I was on my server remotely? so that all links and includes work and so that one folder is considered the root folder?