Some years ago I developed a web app which contained the following code in a php file located in the root folder of the app:
define('APP_ROOT', dirname(__FILE__) . DIR_SEP);
This was to allow the app to be installed in any sub directory of the web docs folder and not necessarily directly in the web root itself, so that the app had a base path from which to dynamically calculate any other paths used in the app.
My test system back then was an Xampp installation running on Windows 7. I no longer have that system, but I believe the path to the htdocs folder was C:xampphtdocs and my app was contained in C:xampphtdocstimesheets. On that system, the value of APP_ROOT was timesheets/, exactly as I wanted.
I know that the customer ran the app on a Linux server and I believe the app was installed in /var/www/timesheets/. So the value of APP_ROOT was timesheets/. I know this worked correctly because he never needed to modify my code.
I am now trying to use the same code again, but my test system is Ubuntu 20.04 with Apache 2.4 and PHP 7.4. The value I am getting in APP_ROOT is /var/www/html/timesheets/, which is causing all my dynamic path calculations to be wrong.
I have tried setting doc_root and open_basedir in php.ini, but I am still getting the full absolute path. I think this must be to do with the server or php configuration, but I have searched the web and cannot find how to correct it.