Feature RTC Language Change Composer Dependency Changed PR-6.0-dev Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
24 May 2025

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:

  • By default the feature is disabled. Create .env in root folder to enable it (can be just an empty file).
  • I tried to keep the variable names in sync with Joomla Docker. If you find something is missing or a typo, please let me know.
  • The installation can be completed with environment variables (except language part). This work with CLI and WEB installer. User can provide all options via environment variables (including admin user info) or a few (like DB only, then installer will ask for missing options).
  • The configuration options provided by environment variables cannot be edited in backend, also via CLI.

Testing Instructions

Test installation, test with Web and in CLI installer

  1. Create .env with DB options:
JOOMLA_DB_TYPE="mysql"
JOOMLA_DB_HOST="Your DB host"
JOOMLA_DB_USER="Your DB user"
JOOMLA_DB_PASSWORD="Your DB password"
JOOMLA_DB_NAME="Your db name"
JOOMLA_DB_PREFIX="DB prefix"

And run installer. You should be asked for Site name, and User information.
Then installation should be completed, as usual.

  1. Create .env with all installation parameters and user information:
JOOMLA_DB_TYPE="mysql"
JOOMLA_DB_HOST="Your DB host"
JOOMLA_DB_USER="Your DB user"
JOOMLA_DB_PASSWORD="Your DB password"
JOOMLA_DB_NAME="Your db name"
JOOMLA_DB_PREFIX="DB prefix"

JOOMLA_SITE_NAME="Test installation"
JOOMLA_PUBLIC_FOLDER=""

JOOMLA_ADMIN_USER="Your admin user"
JOOMLA_ADMIN_USERNAME="Your admin username"
JOOMLA_ADMIN_PASSWORD="Your admin user password"
JOOMLA_ADMIN_EMAIL="Your admin user email"

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)

JOOMLA_DB_TYPE="mysql"
JOOMLA_DB_HOST="Your DB host"
JOOMLA_DB_USER="Your DB user"
JOOMLA_DB_PASSWORD="Your DB password"
JOOMLA_DB_NAME="Your db name"
JOOMLA_DB_PREFIX="DB prefix"

Then visit the site, all should work as before.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:
  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: TBD
  • No documentation changes for manual.joomla.org needed

@Llewellynvdm please have a look if it will be good with Joomla Docker, thanks!

avatar Fedik Fedik - open - 24 May 2025
avatar Fedik Fedik - change - 24 May 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 24 May 2025
Category Repository Administration com_config Language & Strings External Library Composer Change Installation JavaScript Libraries Front End Plugins
avatar Fedik Fedik - change - 24 May 2025
Labels Added: Feature Language Change Composer Dependency Changed PR-6.0-dev
avatar brianteeman
brianteeman - comment - 24 May 2025

dont we already have a PR for this #45070

avatar Fedik
Fedik - comment - 24 May 2025

Correct, but that is incomplete implementation.
This PR is alternative to that.

avatar brianteeman
brianteeman - comment - 24 May 2025

Correct, but that is incomplete implementation.
This PR is alternative to that.

Would be good to comment on that pr etc

avatar richard67 richard67 - change - 24 May 2025
The description was changed
avatar richard67 richard67 - edited - 24 May 2025
avatar richard67
richard67 - comment - 24 May 2025

Correct, but that is incomplete implementation.
This PR is alternative to that.

Would be good to comment on that pr etc

I've allowed myself to add a reference to the issue and a hint to the other PR at the top of the description.

avatar voronkovich
voronkovich - comment - 25 May 2025

Some suggestions:

  1. Use the $_SERVER instead of $_ENV

    Both can be disabled in php.ini, but the $_ENV is disabled by default: https://github.com/php/php-src/blob/201c691fab036b40f8b2ddcfd253fd21089ed799/php.ini-production#L652

    variables_order = "GPCS"

    That's why I use getenv() as a fallback:

    // getenv() is not thread-safe and it can cause segmentaion fault, so we should try $_SERVER first
    $envs = !empty($_SERVER) ? $_SERVER : getenv();
  2. Use the symfony/dotenv

    it's more advanced than the vlucas/phpdotenv and supports some good features like creating environments (dev, prod, test, staging and etc.) and dumping envs in production (.env.local.php).

    Also Joomla already uses some Symfony's components, so why not to use another one?

avatar Fedik
Fedik - comment - 25 May 2025

Both can be disabled in php.ini, but the $_ENV is disabled by default

I tested on PHP 8.1 and 8.4, $_ENV is always present but unpopulated, with variables_order = "GPCS" and variables_order = "EGPCS".

The idea, that the feature is disable by default.
And when User add .env then the Dotenv library will populate $_ENV, and we can use it.

Use the symfony/dotenv

To me Dotenv also looks good, and well supported library. And I would prefer something light.
But if people will insist it could be changed to anything else, easily at any point of time, because it used only in bootstrap.

avatar brianteeman
brianteeman - comment - 25 May 2025

$_ENV is disabled by default on most php installations. When disabled it will return an empty value

avatar voronkovich
voronkovich - comment - 25 May 2025

@Fedik

The idea, that the feature is disable by default.
And when User add .env then the Dotenv library will populate $_ENV, and we can use it.

Then the real environment variables won't work in cases where the $_ENV is disabled.

Sometimes it's very useful to run program with a changed environment. For example:

JOOMLA_PROXY_ENABLED=false php cli/joomla.php core:update
avatar voronkovich voronkovich - comment - 25 May 2025
avatar Fedik
Fedik - comment - 31 May 2025

I added code to check for empty ENV.

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.

I switched shortCircuit to false, should be the same now

avatar Fedik Fedik - change - 31 May 2025
The description was changed
avatar Fedik Fedik - edited - 31 May 2025
avatar voronkovich
voronkovich - comment - 1 Jun 2025

I switched shortCircuit to false, should be the same now

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 .env file. Later, in other PRs, we can add support for either symfony/dotenv or env.dev.

avatar Fedik
Fedik - comment - 1 Jun 2025

Can you move this code block upward outside the if statement? Without it real environment variables won't work if .env file is not present and $_ENV is disabled.

This is intentional. To enable envs on the site User should create an .env file (at least empty), or enable in php.ini (variables_order parameter).
If you have VPS, then last option should not be a problem for you.

For most Users it does not need, so we do not need all that (for now) to be always enabled.
However it can be discussed.

avatar voronkovich
voronkovich - comment - 1 Jun 2025

This is intentional. To enable envs on the site User should create an .env file (at least empty), or enable in php.ini (variables_order parameter).

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 curl doesn't require you to do anything to make envs work. :)

Joomla will be the first one.

avatar Fedik
Fedik - comment - 4 Jun 2025

what's the difference between .env and .env.dev?

First one is for production, second one for development. Or whatever User decide.
It is kind of look up list for which files to look.

In the example:

# .env
JOOMLA_DB_NAME=potato

#.env.dev
JOOMLA_DB_NAME=potato_dev

Will be used potato_dev

Will add to gitignore, but not very important.

avatar Fedik Fedik - change - 4 Jun 2025
The description was changed
avatar Fedik Fedik - edited - 4 Jun 2025
avatar voronkovich
voronkovich - comment - 4 Jun 2025

@Fedik, Your example won't work, because you use Dotenv::createImmutable(). The suffix "immutable" means that the existing environment variables are never changed. You should rearrange the files like this:

Dotenv\Dotenv::createImmutable(JPATH_ROOT, ['.env.dev', '.env'], false)->safeLoad();

Alternatively you can use Dotenv::createMutable(), but it rewrites real envs which is very bad idea.

avatar voronkovich
voronkovich - comment - 4 Jun 2025

@Fedik,

second one for development. Or whatever User decide.

The .dev has a precise meaning: "development". If you want to use it for overriding the .env then I would suggest you to rename it to .env.local (local overrides).

Some examples: Symfony, NextJS

avatar Fedik
Fedik - comment - 7 Jun 2025

It is good as it is.
Can be updated any time later.

avatar SniperSister
SniperSister - comment - 14 Aug 2025

This significant part of our security concept in terms of file access is based upon the idea, that confidential values (as DB credentials) are stored in .php files and are therefore unaccessible via direct webserver calls. This PR and the idea of .env files within the webroot breaks that concept.

So, I see 3 options:

  1. rename the file to .env.php, add a die() statement and adjust the parser to ignore that statement
  2. only allow .env files in a setup, where the JROOT is not the webroot
  3. block access to the file using webserver config files

And to be honest none of the mentioned options is a great solution.

avatar SniperSister
SniperSister - comment - 14 Aug 2025

By default the feature is disabled. Create .env in root folder to enable it (can be just an empty file).

If I read the code correctly, the feature can either be enabled by adding the file or by defining the JOOMLA_ENVIRONMENT variable in $_ENV - correct?

avatar Fedik
Fedik - comment - 14 Aug 2025

Correct.
If you have set your server to enable $_ENV, and add JOOMLA_* environment variables from there, it will be also enabled.

avatar SniperSister
SniperSister - comment - 14 Aug 2025

Ok, thanks for the confirmation! Just wanted to make that I'm not overlooking something

avatar Fedik
Fedik - comment - 14 Aug 2025

About web access to the env file, I think it is valid concern. Even though the feature meant to be for people who know thing or two about what they doing.

Symfony dotenv allows to load .env.php, but it also still allows .env,
I not very wanted to switch to that, but need to look.

avatar dautrich
dautrich - comment - 15 Aug 2025

I tested this locally under Laragon 6.0. Both tests (small .env and complete .env) worked fine with Web.
But using CLI (with the incomplete .env), the process entered a loop when the password was asked. The error log shows (numerous entries):
[15-Aug-2025 18:37:51 UTC] PHP Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in D:\laragon\www\PR-Test\libraries\vendor\symfony\console\Helper\QuestionHelper.php on line 416

avatar Fedik
Fedik - comment - 15 Aug 2025

@dautrich can you share the .env file you use for CLI? without private data, replace it to random strings.
and how did you applied the PR changes for test?

avatar dautrich
dautrich - comment - 15 Aug 2025

Here my .env:

.env.zip

avatar Fedik
Fedik - comment - 15 Aug 2025

Thanks.
I just tried CLI with elements from your env (but with my values), and all went well.
Found little bug, but was different kind of validation. Not an error from QuestionHelper.php.

Not sure, maybe something related to Laragon?
What happen if you enter empty password? Should get:
Screenshot 2025-08-15_22-20-48

avatar dautrich
dautrich - comment - 15 Aug 2025

After I entered my superuser account, the installation immediately went into a loop. I was not able to enter a password.

avatar dautrich
dautrich - comment - 15 Aug 2025

I used the prebuilt package "Joomla_6.0.0-alpha4-dev+pr.45523-Development-Full_Package.zip"

avatar Fedik
Fedik - comment - 15 Aug 2025

After I entered my superuser account, the installation immediately went into a loop. I was not able to enter a password.

@dautrich what happen when you leave empty value for supper user? Do you get validation error kind of "field required" or it also start looping?

I used the prebuilt

Please try new prebuild, I fixed another little error. (Still no idea what happened in your CLI )

avatar dautrich
dautrich - comment - 15 Aug 2025

I tried with the new prebuilt package. Same issue. See Screenshot:

Bildschirminhalt erfassen-1

The error message means "Path not found".

avatar brianteeman brianteeman - test_item - 15 Aug 2025 - Tested successfully
avatar brianteeman
brianteeman - comment - 15 Aug 2025

I have tested this item ✅ successfully on ce36cf3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45523.

avatar brianteeman
brianteeman - comment - 15 Aug 2025

tested using git branch - all worked fine

BUT
I noticed that you are making a change to htaccess.txt
In the past we have always done a post-installation message for changed htaccess.txt but maybe in this case it will be enough to document it in the manual (@SniperSister any thoughts?)

avatar Fedik
Fedik - comment - 16 Aug 2025

I noticed that you are making a change to htaccess.txt

It is not critical for existing websites. Only for new and who decide to use to env. For this the documentation should be enough. I will do it later.

@dautrich I think it something with Laragon, does CLI installation for latest Joomla! 6 nightly build works for you without this error?

avatar dautrich
dautrich - comment - 16 Aug 2025

@Fedik I will try a CLI installation of the newest nightly build under Laragon today.

avatar richard67 richard67 - alter_testresult - 16 Aug 2025 - brianteeman: Tested successfully
avatar dautrich
dautrich - comment - 16 Aug 2025

@Fedik I get the same issue with a Nightly Build of 6.0. Therefore, the issue seems to be related to my Laragon environment. Unfortunately, I don't have on online test site at hand at the moment.

avatar Fedik
Fedik - comment - 16 Aug 2025

@dautrich no problem, thank you for checking

avatar brianteeman
brianteeman - comment - 16 Aug 2025

fyi my tests were with laragon 8

avatar dautrich
dautrich - comment - 16 Aug 2025

fyi I use Laragon 6

avatar dautrich dautrich - test_item - 18 Aug 2025 - Tested successfully
avatar dautrich
dautrich - comment - 18 Aug 2025

I have tested this item ✅ successfully on ce36cf3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45523.

avatar richard67 richard67 - change - 18 Aug 2025
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 18 Aug 2025

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45523.

avatar brianteeman
brianteeman - comment - 18 Aug 2025

@dautrich what changed to make it work?

avatar dautrich
dautrich - comment - 18 Aug 2025

@brianteeman
I tested the CLI part on the Internet (not locally via Laragon). The resulting site is still online under upgrade.hasenritter.de

grafik
avatar brianteeman
brianteeman - comment - 18 Aug 2025

Ok. Must have been a local config issue with your laragon 6 instance

avatar richard67 richard67 - change - 30 Aug 2025
Labels Added: RTC
avatar richard67
richard67 - comment - 30 Aug 2025

I've allowed myself to fix the conflict in the composer.lock file by updating the content hash with composer update --lock.

avatar HLeithner
HLeithner - comment - 31 Aug 2025

This pull request has been automatically rebased to 6.1-dev.

avatar HLeithner HLeithner - change - 31 Aug 2025
Title
[6.0] Variables from non natural environment
[6.1] Variables from non natural environment
avatar HLeithner HLeithner - edited - 31 Aug 2025

Add a Comment

Login with GitHub to post a comment