Reputation: 953
I'm running a composition of two docker images (nginx and php-fpm). Both are working completely fine and I can open my example website but I get one error when using file_get_contents
in PHP:
Warning: file_get_contents(/data/nav.json): failed to open stream: No such file or directory in /var/www/localhost/partials/header.php on line 3
My nginx points to /var/www/localhost
and the data
folder is in the root. Relative URI's like data/nav.json
in my index.php are working as well as full URL's to other websites.
Full source code is available here: https://github.com/muuvmuuv/webserver
I also opened an issue on on GitHub from Docker PHP: https://github.com/docker-library/php/issues/836
I would like to know if this is caused by nginx or php-fpm and why absolute urls are not working.
Upvotes: 1
Views: 4598
Reputation: 43
I had the same issue some time ago and I solve it with relative path:
file_get_contents(getcwd() . '/data/something.json');
Upvotes: 1
Reputation: 36
I think this part from your code is wrong
$url = "/data/nav.json";
you're looking for a file in the wrong directory.
This change worked for me
$url = __DIR__ . "/../data/nav.json";
Upvotes: 2