Skip to content

builtin server read environment variables file #16828

@JohnRDOrazio

Description

@JohnRDOrazio

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:

It would be great if the PHP builtin server could follow a similar pattern, making PHP development more user / development friendly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions