roadrunner-bundle icon indicating copy to clipboard operation
roadrunner-bundle copied to clipboard

$_SERVER['DOCUMENT_ROOT'] is empty

Open asterd opened this issue 3 years ago • 3 comments

Hi,

I have this issue: I've replaced the nginx/php-fpm configuration to use rr. The problem is that the $_SERVER['DOCUMENT_ROOT'] variable is always empty. I've also tried to define them in the server section of the .rr.yaml but without success

server: command: "php public/index.php" env: - APP_RUNTIME: Baldinof\RoadRunnerBundle\Runtime\Runtime - DOCUMENT_ROOT: /usr/local/temp/current/public - TEST: test_var

The TEST variable is visible, the DOCUMENT_ROOT remains empty. What I have to do? Thanks a lot!

asterd avatar Sep 05 '22 07:09 asterd

Hello!

This seems to be a PHP behavior:

$ DOCUMENT_ROOT=hello php -r 'var_dump($_SERVER["DOCUMENT_ROOT"]);'
string(0) ""

It seems ok with getenv():

DOCUMENT_ROOT=hello php -r 'var_dump(getenv("DOCUMENT_ROOT"));'
string(5) "hello"

You can either use another variable name or use getenv(), I'm affraid you cannot workaround it without touching the code.

Baldinof avatar Sep 05 '22 08:09 Baldinof

unfortunately not. I've tried to use getenv("DOCUMENT_ROOT") and it returns false (I'm using a symfony controller and I've tried - for testing purpose - to print out all the $_SERVER configurations and also the getenv("DOCUMENT_ROOT") but in both cases, the result is empty (or false))... Where I have to define the document_root variable? in .rr.yaml it doesn't work.. it seem to be overridden by something. If I try to print the TEST variable, it comes out correctly, and also if I call the variable DOCUMENT_ROOTS.. Any suggestion?

asterd avatar Sep 05 '22 08:09 asterd

I also got false with getenv() the first time but finally it's working. Did you clear the cache?

Declaring in .rr.yaml or .rr.dev.yaml (if you are launching in dev mode) should work, but you can also directly prefix the command.

$ env DOCUMENT_ROOT=hello bin/rr serve -c .rr.dev.yaml

$ curl http://localhost:8080/test
{"docroot":"hello"}

Baldinof avatar Sep 05 '22 08:09 Baldinof