Skip to content

[9.x] Extract ServeCommand env list to static property - #42444

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
rasmuscnielsen:feat/serve-command-env-list
May 19, 2022
Merged

taylorotwell merged 2 commits into
laravel:9.xfrom
rasmuscnielsen:feat/serve-command-env-list

Conversation

@rasmuscnielsen

Copy link
Copy Markdown
Contributor

This PR extracts the hardcoded list of allowed ENV variables from the ServeCommand to a public static property.

Background

Currently the Artisan serve command filters out any host ENV variables that is not explicitly listed in a hardcoded array.

return in_array($key, [
    'APP_ENV',
    'LARAVEL_SAIL',
    'PHP_CLI_SERVER_WORKERS',
    'PHP_IDE_CONFIG',
    'SYSTEMROOT',
    'XDEBUG_CONFIG',
    'XDEBUG_MODE',
    'XDEBUG_SESSION',
]) ? [$key => $value] : [$key => false];

This makes it hard as a developer to add pass additional ENV to the server process - for instance from docker-compose.yml using Sail. The additional ENV can be accessed just fine from CLI but will never be accessible from the browser because it is filtered out from the serve command.

Proposal

Make it easier to allow extra ENV to be passed through to the php built-in server by extracting the above list to a public static property so it can be changed from a ServiceProvider@register/boot function without having to extend and customise the serve command.

Additionally it could be handy to automatically pass through any ENV variable starting with a prefix such as PUBLIC_ or LARAVEL_.
This is similar to what VUE CLI does by making any ENV variables accessible from client javascript if they start with VUE_APP_. This would give the best developer experience as no customisations are needed by the developer.
If there is support for this I'm happy to implement it too.

@taylorotwell
taylorotwell merged commit 534188b into laravel:9.x May 19, 2022
@zolotov88

Copy link
Copy Markdown

Laravel Octane do the same things. It is a reason why do not use it)

salmanarshad321 pushed a commit to salmanarshad321/framework that referenced this pull request Sep 23, 2026
* Extract ServeCommand env list to static property

* formatting

Co-authored-by: Rasmus Christoffer Nielsen <rniels@norlys.dk>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
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

Successfully merging this pull request may close these issues.

3 participants