PHP does not find files when executed in terminal

1

I run the x file normally, in it I add through require_once several other files, and through the browser I execute it normally.

But when I run the file through the terminal it does not find the same files, it does not require_once, why? How do I fix this?

Error example

Fatal error: require(): Failed opening required '../../../../../x.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/versions/actual/includes/servers/php/
    
asked by anonymous 11.11.2015 / 01:03

1 answer

2

You can create global variables:
define('DIR', dirname(__DIR__)); define('ROOT', __DIR__);
When you run through some ampp server you are running the project as if it were a folder, when it runs through the terminal the folder ends up being the root of the server, so you lose references of type ../../ . < With the global variables you will always have an absolute path where your files can be thus being able to reference require_once ROOT.'/pasta/arquivo.php'

    
12.11.2015 / 17:11