R
Railway

✋|help

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"]
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']
$_ENV['AWS_S3_ENV']
What am i doing wrong?
Solution:
nvm. using $_SERVER worked
Jump to solution
PPercy5/22/2023
Project ID: de7aa210-2a7c-457e-9476-6c30744f4f10
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 AUGH
BBrody5/22/2023
also try echoing all the environment vars you know, super basic debugging stuff 🙂
MMedim5/22/2023
...not possible lmfao
BBrody5/22/2023
it has to be
MMedim5/22/2023
yeah, blame slim-php/php-fpm/composer cant log shit there
BBrody5/22/2023
log it somewhere else
MMedim5/22/2023
trust me, i can't 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 obviously dont use the real credentials for this type of testing
BBrody5/22/2023
^
MMedim5/22/2023
.. it crashes on the first one but i tried $_ENV gonna try $_SERVER and getenv also .. 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); ?>
<?php print_r($_ENV); ?>
MMedim5/22/2023
hmm 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 cause php-fpm can't do it by itself it seems https://github.com/vlucas/phpdotenv
BBrody5/22/2023
kinda cringe php
MMedim5/22/2023
it worked flawlessly 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

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Error : Render template thymeleafHello everyone, I am currently in need of assistance with a 404 error issue while deploying my SprinCan't access api url (nestjs project)So on my local env if I access localhost:port/api I can see api swagger documentation. Also I can docan not find a way to add a file in the deploymentHi, I am trying to deploy a node js backend which uses firebase auth. For that i need to add a googlDoes "wipe plugin data" delete all data from all environments?Error: Cannot find module '/app/dist/index.js'Hello, I have not made any significant changes to my app, but all of a sudden the build is failing. Trying to get Shopware Running please helpHi there I am trying to get Shopware Running on Railway. I have created a Dockerfile on my repo but redis and postgres loggingI want to turn on redis and extensive postgres logging. How do I do that ?Intermediate step with postgres to deploy a crud app (express, ejs)https://stackoverflow.com/questions/74964944/pern-stack-deploying-to-railway I've been searching evCan I go to a prepaid plan instead of usage based?Hi, I noticed that I am on the usage plan for on the Developer Plan, but I want to do prepaid for blogin problem.Railway prevents me from login in randomly, what happens?Increase Free hours from 500 to 754/ monthI wanted to change my free hours from 500 to 745 hours / month with decreased memory limit to 0.75 oRailway cron jobsI am going to create a cron job using Railway by following this blog post. https://blog.railway.app/Questions about the Developer planIf I add a card to unlock the developer plan, then remove the card, will I lose access to the plan?503/Cors error deploying PERN App for first timeI'm having both a CORS error and 503 in my sign-in request from client to server, both hosted on RaiProblem installing dlib library in my railway environmentProject ID: 841bbdef-4033-4e74-953c-030beb316802 Project code: https://github.com/SeifShaat/Divine-I am trying to deploy a react-scripts app the build is done but it is taking forever to deployit has been 15 mins now and still nothing it was 20 mins earlier when I decided to change http-servegunicorn: command not found (Django)I have gunicorn in my requirement.txt file in my django application i am trying to deploy but it thrError: Unable to access jarfile target/*jarProject ID: a7e9764d-13dd-40c9-a428-41835b4bc576 I have a project when deploy Java Spring Boot, can DeviantArt RSS is blocking Railway's IPI have a bot that pulls a user's art from the RSS feed associated with their account. For a couple oquestionsso i hv a question if i hosted a website on localhost1400 smtg like tht how do i view tht website