PHP function works locally, not on server

So, I’d assumed the local and server versions of things would be identical, but I’m finding that locally, I can use the php function ‘file_get_contents()’, and on the server, it returns bool(false). Typing the path to the file in question into the url bar works just fine, so its not a missing file.

There is a potentially related issue in the loading of large json files (with the WP-API), in that they timeout and nginx gives a 502 error. Other json paths and post types work fine, just one case where it returns over 200 posts.

Ideas anyone? I’ve heard it might have to do with a php.ini setting somehow, but again, why would the local Vagrant box be different from the ansible deployed server?

There are a few minor settings between development and production but nothing that should change file_get_contents.

You can see the variables changed in development here: https://github.com/roots/trellis/blob/875b58ab3672727f7068233444be2bbc080b321f/group_vars/development#L33-L38

1 Like

That’s what I thought. Well, ok, to put it to bed once and for all, what DO droplet should I start with? In the past, I couldn’t get things to work unless I chose their LEMP stack box, but I’m thinking that’s now what’s causing the disparity.

You should not choose any apps to preinstall, it should be a base, stock Ubuntu box

1 Like

Well, still not working, I’ll have to dig more into this.

Ok, I finally figured it out!

The remote website is not live yet, I’m just using my hosts file to point the local domain at the DO droplet. The php function in question fires from the server, so obviously the file asked for returns a 404.

To fix this I just had to properly localise my file request so it was path relative, not url relative, which I did with TEMPLATEPATH . What a headache! Thanks for nudging me in the right direction guys.

1 Like