My API can't read env vars

MMedim5/22/2023
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:
FROM composer:2.4.4 AS composer
FROM php:7.4-fpm as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN apt-get update
RUN apt-get install -y \
    nginx \
    supervisor \
    zlib1g-dev \
    libzip-dev \
    libjpeg-dev \
    libxml2-dev \
    libonig-dev \
    libicu-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev
RUN docker-php-ext-install gd soap zip intl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg

FROM base as config
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

FROM config as app
ARG AWS_S3_ID AWS_S3_SECRET AWS_S3_REGION AWS_S3_MAIN_BUCKET AWS_S3_ENV
ENV AWS_S3_ID=$AWS_S3_ID AWS_S3_SECRET=$AWS_S3_SECRET AWS_S3_REGION=$AWS_S3_REGION AWS_S3_MAIN_BUCKET=$AWS_S3_MAIN_BUCKET AWS_S3_ENV=$AWS_S3_ENV
WORKDIR /var/www/html

COPY . .

RUN composer install --ignore-platform-req=ext-bcmath --no-dev

EXPOSE 8080
CMD ["/usr/bin/supervisord"]


Im reading the vars in code using
$_ENV['AWS_S3_ENV']


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