0
votes

I setup a brand new skeleton Symfony project and added the API Platform package. I created an entity with make:entity, created a migration, was able to successfully execute the migration, and can now see the table in my database.

From the API swagger documentation page (and via curl request in my local terminal), attempts to execute a basic GET request for all entity resources fails. The error appears to result from the API using the DATABASE_URL from the .env file, not the DATABASE_URL that exists as an actual environment variable. This is easy to see since the .env file is using MySQL whereas my actual environment variable is using PostgreSQL.

Executing printenv shows the proper value, bin/console debug:container --env-vars shows the proper value, and clearly Doctrine recognizes the proper environment variable because the migration executed successfully.

Furthermore, if I remove the DATABASE_URL line from the .env file, simply attempting to load the API results in a 500 error stating Environment variable not found: "DATABASE_URL".

What is causing the API Platform to ignore my environment variable while Symfony and Doctrine recognize it just fine?

1

1 Answers

0
votes

This turned out to be a problem in the docker configuration. When using s6 overlay as a process supervisor, the services.d file that runs PHP needs to use the with-contenv helper in order to have environment variables available.

Replacing

#!/usr/bin/execlineb -P
php-fpm -R --nodaemonize

with

#!/usr/bin/with-contenv sh
exec php-fpm -R --nodaemonize

allowed PHP to see the environment variables set within my docker-compose file and the API platform started returning results as expected.