php-pm-httpkernel icon indicating copy to clipboard operation
php-pm-httpkernel copied to clipboard

Environment variable not found: "DATABASE_URL

Open krajcikondra opened this issue 3 years ago • 4 comments

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

krajcikondra avatar Feb 06 '22 12:02 krajcikondra

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 avatar Jul 06 '22 07:07 sweedheart

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()

sweedheart avatar Jul 07 '22 06:07 sweedheart

I created a pull request for this bug: https://github.com/php-pm/php-pm-httpkernel/pull/186

xarem avatar Jul 20 '22 21:07 xarem

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

j-mahlke avatar Jun 28 '23 08:06 j-mahlke