New installation, "" is invalid environment under PHP-FPM
I just saw the first stable release of the app package for Yii3 and thought to try it out myself.
I run composer create-project yiisoft/app myproject locally in my Linux box, I corrected the permissions so that the httpd user can write in the folders and when I click on the public directory in my browser, I get this error:
Fatal error: Uncaught RuntimeException: "" is invalid environment. in /home/xxxxx/public_html/myproject/src/Environment.php on line 77
If I run yii serve from the cli, it works, since I pass APP_ENV as a environment variable before the command.
But how the heck do I do this in the web application? I see no reference in the docs about what to do, let's say I'm a newbie user and I want to try the framework out. It fails miserably, and I will look somewhere else.
I've been using Yii 1.1 and 2.0 as my framework of choice for all my PHP projects for the last decade or so, but Yii3 seems like an alien thing to me. Am I too old to deploy it under the classic php-fpm-Apache installation that only other deployment types are now of relevance (like docker)?
I guess the docs could be improved.
Environment variables are quite cumbersome to use without any isolation such as Docker. If you have only a single project, defining variables locally should do such as
export APP_ENV=dev
and then adding env APP_ENV to the very top of your Nginx config.
Also try fastcgi_param APP_ENV dev; in your location block. Not sure if it will work well since I haven't touched "classic" setups for a while. But if I'd still used it, I'd have used it this way.
Can I hard-code somewhere in the project files the APP_ENV environment? This is totally different compared to the Yii 2 way, where you changed the index.php file where you have the YII_DEBUG and YII_ENV constants. If I don't need isolation and the same installation (PHP-FPM/Apache/Nginx) is used for several projects, which way should I follow?
Upgrading from Yii 2 needs more details.
Can I hard-code somewhere in the project files the APP_ENV environment? This is totally different compared to the Yii 2 way, where you changed the index.php file where you have the YII_DEBUG and YII_ENV constants. If I don't need isolation and the same installation (PHP-FPM/Apache/Nginx) is used for several projects, which way should I follow?
Hard-code way is use default value instead of exception in Environment::setEnvironment() method:
https://github.com/yiisoft/app/blob/5705eb836ca8536ee9ec52565ee54510a6563c40/src/Environment.php#L73-L82
Or another way — add $_ENV['APP_ENV'] = 'dev'; to /src/autoload.php before Environment::prepare();.
Can we not close this yet, this is a serious issue. I've just ran into the same problem, developing on a Debian 13 VM on Proxmox. Not everybody is running Docker and there's no reason for it, when using Plesk with a lot of vHosts. Also with clients having only vHosts and no access to their server configuration, modifying core files seems strange.
@bigrepository reopened. btw., template is not "core" files. Once you've used it, this code is all yours.
If environment don't support environment variables' setting, vlucas/phpdotenv usage will be good way: initiate it in /src/autoload.php before Environment::prepare();.
Some good topics for a cookbook.
https://github.com/yiisoft/app/pull/399
поддерживаю поставил приложение через DDEV 15 минут ломал голову куда ENV прописать пока в этот issue не попал...