PHP does not find files when running on the terminal

Asked

Viewed 96 times

1

I run the file x normally, in it I include through require_once various other files, and through the browser I run it normally.

But when I run the file by terminal it does not find the same files, it gives error in require_once, why? How to fix it?

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/

1 answer

2


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.