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?
![](https://answer-overflow-discord-attachments.s3.amazonaws.com/1110262016460996720/image.png)
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
![wat](https://cdn.discordapp.com/emojis/786868710791053312.png)
show me your service variables
![](https://answer-overflow-discord-attachments.s3.amazonaws.com/1110263396475093125/image.png)
show me how your code is accessing the variables
![](https://answer-overflow-discord-attachments.s3.amazonaws.com/1110263609222758441/image.png)
whats this $_ENV thingy
to access the env var
doesnt php use getenv
just if u wanna mutate it i guess
![](https://answer-overflow-discord-attachments.s3.amazonaws.com/1110264137327575101/image.png)
nvm
try it?
but theres also ![AUGH](https://cdn.discordapp.com/emojis/659192186520207381.gif)
![AUGH](https://cdn.discordapp.com/emojis/659192186520207381.gif)
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 ![FeelsCry](https://cdn.discordapp.com/emojis/722309711847882832.png)
![FeelsCry](https://cdn.discordapp.com/emojis/722309711847882832.png)
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