Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable not found: "DATABASE_URL #182

Open
krajcikondra opened this issue Feb 6, 2022 · 4 comments
Open

Environment variable not found: "DATABASE_URL #182

krajcikondra opened this issue Feb 6, 2022 · 4 comments

Comments

@krajcikondra
Copy link

When I run php pm with test environment

vendor/bin/ppm start --config=ppm.json --app-env=test

I got following exception:

An exception was thrown by the bridge. Forcing restart of the worker. The exception was: Symfony\Component\DependencyInjection\Exception\EnvNotFoundException: Environment variable not found: "DATABASE_URL". in /var/www/html/vendor/symfony/dependency-injection/EnvVarProcessor.php:172

My .env.test file:

KERNEL_CLASS='App\Kernel'
APP_SECRET='mysecret'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
MAILER_DSN=null://localhost
APP_ENV=test
DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"

Do I start ppm server properly? I use symfony 5.2

@sweedheart
Copy link

Having the same problem, although I am running ppm inside a Docker container and symfony 6.1.

Command:
/ppm/vendor/bin/ppm start \ --workers=1 \ --host=0.0.0.0 \ --debug 1 \ --socket-path=/tmp \ --static-directory=public/ \ --pidfile=/ppm/ppm.pid

When running the same command from a local console, symfony parses the .env (or .env.local.php) file correctly and the env vars are listed in webprofiler (in Server Params).

When running in docker, the webprofiler shows "no data". I have to pass all variables as docker environment variables in docker-compose file.
.env and .env.local.php are bind-mounted into the container (the whole project directory).

In docker:
ppm_in_docker

In debian bash:
ppm_without_docker

composer.json for ppm:
{ "require": { "php-pm/httpkernel-adapter": "dev-master", "php-pm/php-pm": "dev-master" } }

Dockerfile:
`FROM php:8.1-alpine AS php

ENV OPCACHE_ENABLE="On"
ENV PHPPM_WORKERS=1
ENV APP_ENV="prod"

ENV STATIC_DIR="public"
ENV PPM_DEBUG=0

RUN apk add
icu-dev
icu-data-full
libpq-dev
bash

RUN docker-php-ext-configure intl
&& docker-php-ext-install
pdo_pgsql
opcache
intl
pcntl

COPY build/php/config/* /usr/local/etc/php/conf.d/

RUN mkdir -p /ppm

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY build/php/ppm/composer.json build/php/ppm/composer.lock /ppm/

WORKDIR /ppm

RUN composer install

RUN mkdir -p /var/www

WORKDIR /var/www

CMD /ppm/vendor/bin/ppm start
--bootstrap=symfony
--bridge=HttpKernel
--workers=${PHPPM_WORKERS}
--host=0.0.0.0
--debug ${PPM_DEBUG}
--socket-path=/tmp
--static-directory=${STATIC_DIR}/
--pidfile=/ppm/ppm.pid

EXPOSE 8080`

@sweedheart
Copy link

The problem is related to how .env files are parsed in symfony:
When APP_ENV is already set, no .env file is parsed. The symfony bootstrap for php-pm does the same, see PHPPM\Bootstraps::getApplication()

@xarem
Copy link
Contributor

xarem commented Jul 20, 2022

I created a pull request for this bug: #186

@j-mahlke
Copy link

I recommand to include your env file into the docker-compose service like described here:
https://docs.docker.com/compose/environment-variables/set-environment-variables/#use-the-env_file-attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants