2

Any idea what could cause a PHP file to execute fine in the browser, but give an error when run in the command line interface?

So to be specific, when I visit mysite.com/script.php in a browser, all is well.

When I execute php -f /var/www/mysite.com/public_html/script.php I get an error that one of my required files cannot be found.

So, the error message gives a lot of insight, but I am confused because it works as intended in the browser with no error, so I have no idea what could cause this behavior. Any ideas?

sotirov
  • 4,455
Zack
  • 123
  • 1
    Without the error message, I can only suggest that your process environment differs. Type env to see yours. – waltinator Sep 07 '15 at 01:02
  • the error message: PHP Warning: require(../php/cloudinary/Cloudinary.php): failed to open stream: No such file or directory in /var/www/mysite.com/public_html/script.php on line 7 I looked at my process environment but didn't see anything off. And the error message is interesting, because the file obviously exists, as it works in browser and relies on the script its claiming isn't existent. – Zack Sep 07 '15 at 03:01
  • 1
    By starting with ../, which is relative to the current working directory of the process, the require will only work if you are in the right directory. If you have control of the script, change it to use the full, absolute path starting at /, – waltinator Sep 07 '15 at 05:34
  • @waltinator Please, post that as an answer. – Eric Carvalho Sep 08 '15 at 16:22

1 Answers1

2

By starting with ../, which is relative to the current working directory of the process, the require will only work if you are in the right directory. If you have control of the script, change it to use the full, absolute path starting at /,

A.B.
  • 92,275