I am not a developer and don’t have deep technical knowledge of Joomla’s internal workings, but I ran into an issue with configuration.php while troubleshooting a restored Joomla site.
After restoring a backup to a different domain on the same server, I noticed that configuration.php contained unexpected variables that I had never seen before. These variables were not part of a clean Joomla installation. I tried to track down where they were coming from and discovered that they appear when Joomla’s Configuration API is used to modify settings.
When using the Joomla Configuration API (Factory::getApplication()->getConfig()) to modify and save site settings, Joomla unexpectedly includes additional variables in configuration.php. These variables do not seem to be explicitly set but appear when Joomla writes the file.
Install a fresh Joomla 5.x instance.
Use the following code to modify a setting via the Joomla API:
use Joomla\CMS\Factory;
$config = Factory::getApplication()->getConfig();
$config->set('sitename', 'New Site Name'); // Modify a setting
$newConfig = $config->toString('PHP', ['class' => 'JConfig']);
file_put_contents(JPATH_CONFIGURATION . '/configuration.php', $newConfig);
Open configuration.php and inspect the file.
Only intended changes should appear in configuration.php (e.g., the modified sitename).
No additional variables should be included.
Joomla adds extra variables to configuration.php, including:
public $execution = array(...);
public $uri = array(...);
public $session = true;
These variables were not manually added but appeared after Joomla saved the configuration.
Joomla incorrectly saves request-related variables, polluting the config file.
Joomla 5.2.5
PHP 8.3.16
I think there might have been an issue about this in the past by I was not able to find it.
Labels |
Added:
No Code Attached Yet
|
It looks like runtime properties are leaking into configuration.php. Is filtering out these properties before saving in configuration file using a new function a good way to proceed ?
sorry that is completely wrong.
The values being added are perfectly valid. The ones you mention are just some of the additional values being added.
It's not a problem as without those values Joomla uses default values (the same as written when you press save in global config). However I do agree that ideally all the possible settings should be entered in configuration.php during installation and it is confusing (as you discovered) when they are not. they should also be in configuration.php-dist
It looks like runtime properties are leaking into configuration.php. Is filtering out these properties before saving in configuration
file using a new function a good way to proceed ?