filter_input(INPUT_SERVER,'DOCUMENT_ROOT'); not working in local environment
I’m new to PhpStorm, I’m trying to built a new development environment.
My online (“production”) environment is a shared hosting using Linux.
At home I use Windows 10.
My new environment so far has:
- Windows 10
- PhpStorm
- Php 7.3.3 VC15 x64 Thread Safe unzipped somewhere on my my hard drive.
- exe refered as interpreter in PhpStorm
- php_xdebug-2.7.0-7.3-vc15-x86_64.dll set has debugged in php.ini
In my php code I have
filter_input(INPUT_SERVER,'DOCUMENT_ROOT');
It returns null (or something that is empty).
When I paste it in the terminal is says “'filter_input' is not recognized as an internal or external command, operable program or batch file.”
Well, maybe that’s the type of terminal I’m expecting but the fact that it returns null is a problem.
What should I change so that it returns the same value as in my online environment?
I have tried solutions from https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null
including adding "variables_order = "GPCSE"" to php.ini, but it didn’t solve the problem.
Writine filter_var(getenv(‘'DOCUMENT_ROOT ')); instead but it didn’t solve the problem … yet I want to code for my online environment not to adapt my code to my development environment.
Regarding the answers that talk about FastCGI, I have no idea what it is and if I’m using it.
How could I correct this in my local/development environment?
Thank you
Please sign in to leave a comment.
Did you try a workaround mentioned there: https://stackoverflow.com/a/36205923/8020009?
Other than that - you would have to google for FastCGI & then rebuild your local PHP without fastcgi, unfortunately.
Thank you.
Well no, I haven't tried that fix because, as I suggested in my original post, I don't want to write code specific to development environment.
I'm a bit confused about that FastCGI thing because looking at php.ini and PhpStorm output nothing explicitely indicate that I am use "Fast"-cgi. I could do a deeper search about it though.
But, I found another way around ... I'll post it soon in a distinct answer.
Here some way I found:
Apparently, when you click on the debug button, PhpStorm does not run PHP scripts as if they were accessed via a server, hence some values like DOCUMENT_ROOT are not filled.
However, when accessing to http://localhost:63342/[path]/[filename] , DOCUMENT_ROOT indeed contains the expected value.
Note: using localhost (or other names) may require editing \Windows\System32\Drivers\Etc\hosts file.
I have also set a "server" in PhpStorm (Settings > Languages & Frameworks > PHP > Servers ) on localhost:80 but this one seems ineffective and unrelated, you probably don't need it, not sure.
EDIT: I just realised this is actually only a partial way around because if I use this, debug seem ineffective, breakpoints are not triggered.