My API can't read env vars
hey, im trying to deploy a php-fpm api and i got a local .env file and i got the same .env at the railway project vars, but my api doesn't seem to be able to access it
My custom dockerfile:
Im reading the vars in code using
What am i doing wrong?
45 Replies
Project ID:
de7aa210-2a7c-457e-9476-6c30744f4f10
de7aa210-2a7c-457e-9476-6c30744f4f10
oh so you arent actually using these variables during build, only after the app has started
yeye
then you dont need them in the dockerfile at all
show me your service variables
show me how your code is accessing the variables
whats this $_ENV thingy
to access the env var
doesnt php use getenv
just if u wanna mutate it i guess
nvm
try it?
but theres also
also try echoing all the environment vars
you know, super basic debugging stuff 🙂
...not possible
lmfao
it has to be
yeah, blame slim-php/php-fpm/composer
cant log shit there
log it somewhere else
trust me, i can't
gotta be trial and error
bruh slap a single index.php file in an /app folder and print the environment variables
yeah, thats a good option
not possible my ass
not to console atleast
prints to browser window, it dont matter
obviously dont use the real credentials for this type of testing
^
.. it crashes on the first one
but i tried $_ENV
gonna try $_SERVER and getenv also
.. nothing works
Solution
nvm. using $_SERVER worked
now u ask me why? idk
hmm
I'm wondering why $_SERVER instead of $_ENV
youve mucked something up somewhere
yeah I needed a custom package to read env vars
cause php-fpm can't do it by itself it seems
https://github.com/vlucas/phpdotenv
kinda cringe php
it worked flawlessly
thanks @Brody
no problem, though i dont know if i helped
since i can't pay you, here is a 🌟 for you
awh thanks
gonna close this thread