-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Description
If the builtin server (php -S localhost:PORT
) could automatically detect environment variable files such as .env
, .env.development
and load the key => value pairs such that they are then available in the $_ENV
magic variable array, it would make local development much easier and more similar to other languages such as node or ruby.
Say I spawn the bultin server for a local API backend on port 8000. Then I want to spawn another builtin server for a frontend, which however knows nothing about which port the API backend is being served on. If I could place an environment variable file in my frontend project .env.development
with API_PORT=8000
, the frontend could then have $_ENV['API_PORT']
with a value of 8000
and I could use that in my frontend logic to determine how the frontend should interface with the API backend.
I might add, that spawning a localhost instance with the builtin server could also automatically set an environment variable of $_ENV['development']=true
.
Docker, React and NextJS all follow similar patterns of loading environment variables from .env
files:
- https://create-react-app.dev/docs/adding-custom-environment-variables/
- https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
- https://docs.docker.com/compose/how-tos/environment-variables/set-environment-variables/
It would be great if the PHP builtin server could follow a similar pattern, making PHP development more user / development friendly.