R
Join ServerRailway
✋|help
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?
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?
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 $_SERVER

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
nope
^
.. 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
<?php print_r($_ENV); ?>
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
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