-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[6.0] Variables from non natural environment #45523
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
base: 6.0-dev
Are you sure you want to change the base?
Conversation
Conflicts: composer.json composer.lock
I've allowed myself to add a reference to the issue and a hint to the other PR at the top of the description. |
Some suggestions:
|
I tested on PHP 8.1 and 8.4, The idea, that the feature is disable by default.
To me |
$_ENV is disabled by default on most php installations. When disabled it will return an empty value |
Then the real environment variables won't work in cases where the Sometimes it's very useful to run program with a changed environment. For example: JOOMLA_PROXY_ENABLED=false php cli/joomla.php core:update |
It would be a BC break, because the symfony/dotenv works slightly different. It merges .env files, but the vlucas/phpdotenv doesn't change already loaded values. Example# .env
HELLO='env' # .env.dev
HELLO='env.dev' vlucas/phpdotenv:<?php
require 'vendor/autoload.php';
Dotenv\Dotenv::createImmutable(__DIR__, ['.env', '.env.dev'])->safeLoad();
// Outputs: 'env'
echo $_ENV['HELLO']; symfony/dotenv:<?php
require 'vendor/autoload.php';
(new Symfony\Component\Dotenv\Dotenv())->bootEnv(__DIR__ . '/.env', 'dev');
// Outputs: 'env.dev'
echo $_ENV['HELLO']; |
I added code to check for empty
I switched |
Nothing is changed. It still works like in the example above. I've created a repository with an example: https://github.com/voronkovich/dotenv-example. You can't make the vlucas/phpdotenv works the same way as the symfony/dotenv (believe me, I've already tried). I suggest to simplify this PR and load only the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give you my use case why I want to use real environment variables.
I have a VPS with several dozen Joomla installations, and for some reason, I need to use a proxy to load updates. Currently, I have to manually edit every configuration.php
file and set the proxy settings. With environment variables, I could set all these settings in one place: /etc/environment
(or maybe in /etc/environment.d/00-joomla.conf
):
JOOMLA_PROXY_ENABLE=true
JOOMLA_PROXY_HOST='proxy_host'
JOOMLA_PROXY_PORT='proxy_port'
JOOMLA_PROXY_USER='proxy_user'
JOOMLA_PROXY_PASS='proxy_pass'
Also it would be great to set common settings for SMTP, caching, redis, disable errors_reporting an so on using envs. All in one place.
This is intentional. To enable envs on the site User should create an For most Users it does not need, so we do not need all that (for now) to be always enabled. |
I've never seen an application that requires enabling an option to make environment variables work. Because it doesn't make sense. In Symfony everything works out of the box. In Laravel everything works out of the box. In WordPress everything works out of the box. Even Joomla will be the first one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fedik, what's the difference between .env
and .env.dev
? In what cases should the latter be used? Why is the .env.dev
not added to .gitignore
file?
First one is for production, second one for development. Or whatever User decide. In the example: # .env
JOOMLA_DB_NAME=potato
#.env.dev
JOOMLA_DB_NAME=potato_dev Will be used Will add to gitignore, but not very important. |
@Fedik, Your example won't work, because you use Dotenv\Dotenv::createImmutable(JPATH_ROOT, ['.env.dev', '.env'], false)->safeLoad(); Alternatively you can use |
It is good as it is. |
Pull Request for Issue #36898 .
Alternative to PR #45070 .
Summary of Changes
This is complete (I hope) implementation of environment variables in Joomla.
Key points:
.env
in root folder to enable it (can be just an empty file).Testing Instructions
Test installation, test with Web and in CLI installer
.env
with DB options:And run installer. You should be asked for Site name, and User information.
Then installation should be completed, as usual.
.env
with all installation parameters and user information:And run installer. You will not be asked for Site name, and User information.
The installation should be completed, as usual.
Test the existing site
Create
.env
with DB options, and copy options from configuration.php.(skip this step if the site was installed with use of .env)
Then visit the site, all should work as before.
Link to documentations
Please select:
@Llewellynvdm please have a look if it will be good with Joomla Docker, thanks!