-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Artisan serve ignores REAL environment variables #45450
Comments
Hey there, Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out. Thanks! |
It's a function, not a bug! The So, in /**
* Start a new server process.
*
* @param bool $hasEnvironment
* @return \Symfony\Component\Process\Process
*/
protected function startProcess($hasEnvironment)
{
$process = new Process($this->serverCommand(), public_path(), collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
if ($this->option('no-reload') || ! $hasEnvironment) {
return [$key => $value];
}
return in_array($key, static::$passthroughVariables) ? [$key => $value] : [$key => false];
})->all());
$process->start($this->handleProcessOutput());
return $process;
} Because of this, only the environments defined in @driesvints , it is possible to reopen the issue? Or can we suggest a new feature to customize which environment variables are loaded? Important: I'm using Laravel v10.14.1 |
For documentation purposes, we can rewrite the php artisan make:command ServeCommand Now, extends the namespace App\Console\Commands;
use Illuminate\Foundation\Console\ServeCommand as BaseServeCommand;
class ServeCommand extends BaseServeCommand
{
/**
* The environment variables that should be passed from host machine to the PHP server process.
*
* @var string[]
*/
public static $passthroughVariables = [
'APP_OTHER_ENV', # The new environment
'APP_ENV',
'IGNITION_LOCAL_SITES_PATH',
'LARAVEL_SAIL',
'PATH',
'PHP_CLI_SERVER_WORKERS',
'PHP_IDE_CONFIG',
'SYSTEMROOT',
'XDEBUG_CONFIG',
'XDEBUG_MODE',
'XDEBUG_SESSION',
];
} So, if you are using Laravel Sail, you will able to add the # For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
APP_OTHER_ENV: 'new_environment' # The new environment
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}'
volumes:
- '.:/var/www/html'
networks:
- sail
networks:
sail:
driver: bridge
|
I ended up creating a custom serve command as @MateusBMP suggested. Worked perfectly for my use case locally. Thanks. |
Description:
I run Laravel via Sail (version 8.1) and supervisord is used to serve. However, while the variables from
.env
clearly show up and can be used, this is not true for the REAL system/server environment variables. According to docs these should overwrite the variables but nope. I have tried everything but I cannot let my docker/supervisord inject any variables into Laravel. However, this is the normal application for docker: Inject something.Steps To Reproduce:
My supervisord.conf is this (sail default for 8.1)
As you can see, I add test vars at various places. I also run
env
above and, in the log, I see that this environment variable is correctly within the env. The environment variables are everywhere...However, once in Laravel (whether I use
getenv
, checkconfig
, manually useenv()
function for a specific environment variable, it does not matter), I cannot access ANY of myTEST_VAR_x
variables.It cannot be so difficult to just pass in environment variables and use them in PHP? This is no issue in any other programming language/framework I know of including Python/Django, Go, Rust, custom C++, RuR, Java, JS Node, ...
The process of how environment variables go from the system/server environment into Laravel does not seem to be documented well either. Also, each google search for "environment variables" in PHP silently assumes that always
.env
is meant... PHP's way of adding some EXTRA variables that are actually not what the whole world understands by environment variables - thus neatly overriding a well-known and important concept and making it un-google-ble.For anyone else reading this: My shitty workaround is for now to have some placeholder in
.env
file and run in supervisord ased
replacing the content of this variable.Sorry, I'm exhausted and frustrated.
But I appreciate very much any help...
The text was updated successfully, but these errors were encountered: