Consider implementing the phpdotenv usage to handle configuration #8015
Replies: 22 comments 1 reply
-
As mentioned by @marcbria on Slack:
We could try to implement the phpdotenv at |
Beta Was this translation helpful? Give feedback.
-
Also, currently our phpunit tests aren't running in one separated "disposable" environment. Every test uses the configuration data (including database config) from the main config.inc.php file. |
Beta Was this translation helpful? Give feedback.
-
Can you give some code examples showing the limitations you're hitting with the current |
Beta Was this translation helpful? Give feedback.
-
The one that Laravel uses? |
Beta Was this translation helpful? Give feedback.
-
One good thing about .ini files is that we can leave comments there =] I think About adding support to extend/overwrite configurations using environment variables:
In general, I don't have anything against replacing local code by external libraries, given it will have free community/support/documentation/tests. |
Beta Was this translation helpful? Give feedback.
-
I would be inclined to draw on Laravel's configuration pattern, in part because it aligns more of our code base with the same underlying framework. They do support environment variables as well, and we can write PHP code into the config area if we really needed to. Am I right in thinking the main issue with the current approach is that you'd liike to be able to define some environment variables on the command line, for Docker or PHPUnit? My one hesitation with going fully with phpdotenv is that everything is an environment variable. Should every configuration variable we use be an environment variable? |
Beta Was this translation helpful? Give feedback.
-
In the docker channel in slack we had a nice conversation a month ago about config.inc.php with Andrew and @asmecher Summarizing, we said: There are 4 things other well-known projects are doing to have a better configuration files that I think we can learn about:
phpdotenv project covers 1, 2 and 3 and in their site they explain why .env vars are a good idea: Andrew (I need to find his github user) extended this saying: 2 is a step up from 3 and 4. Setting your configuration in your database doesn’t make your code a separate entity from your data as it causes the configuration to bleed into the data. This is one thing that the ini file approach has going right for it. I really don’t think that putting the configuration into the database is a good plan (you’ll then, as the SO answer mentions, have two sets of configuration too… some in the database, some … wherever the database credentials are stored).
I see huge benefits in testing, docker and cloud environment but... Even the potential you release using environment variables is really big... (you can also change variables that are not from OJS) my lack of knowledge about OJS code makes me feel insecure about the side-effects.
I got the same question, but Andrew made his point. |
Beta Was this translation helpful? Give feedback.
-
Thanks for bringing all that in @marcbria, that's really helpful!
I agree with this. WordPress stores a lot of settings in the database and this makes it really hard to deploy staging/production environments.
Yeah, I'm curious about this side of it. It may be that some shared hosts prevent or limit the ability to modify the environment. It would be interesting to explore what impact this might have. Laravel's configuration pattern does support choosing whether to take a config option from the environment. And has built-in support for defining things differently based on common deployments (locale, staging, production). |
Beta Was this translation helpful? Give feedback.
-
Same happened in Drupal 10 years ago, and they moved out from DB to config files again. :-)
Nate, if I understand well, you like Henrique's proposal to integrate phpdotenv but you propose to do it in the Laravel's way? The only BUT is we are concerned about potential security issues and brand new conflicts... but at same time this is becoming the new standard so we are not the first ones to walk this path. Some articles talking about those same security concerns:
Guys, thanks you all for your work. |
Beta Was this translation helpful? Give feedback.
-
Using the In one of my previous companies, we've developed a support class to handle data from edit And I don't even want to mention the code smell related to the |
Beta Was this translation helpful? Give feedback.
-
It looks like Laravel 8 uses phpdotenv and also now reads from the $_ENV super global. Maybe there's not a distinction to be made, now, and we can experiment with using phpdotenv but configuring it similar to Laravel? |
Beta Was this translation helpful? Give feedback.
-
Another option to consider, which would keep the |
Beta Was this translation helpful? Give feedback.
-
Not sure about this Jonas. It's true that TOML (or YAML) are becoming the new config-file standards, but OJS admins are familiar with ini syntax and the config upgrade will be easier. I'm afraid a change like this could generate an avalanche of requests in the forum. |
Beta Was this translation helpful? Give feedback.
-
If you keep both flavors? Inspired on spring java framework, your config could be like this: If the system admin are from old school, they will happy to connect with ssh and hardcode the values:
But if the sysadmin is a generation z devops engineer and wants to deploy in several nodes/environments the same ojs with a puff using docker or some crazy technology
Then at the moment of read the ini file: pkp-lib/classes/config/Config.inc.php Line 71 in a2db11e or in the parser the algorithm should be like this:
I implemented that algorithm on java and nodejs. Some php developer should be able to do it. Finally if you add this feature, would be fulfilling the third commandment of 12factor https://12factor.net/config and the use of docker and modern technologies will be easy. |
Beta Was this translation helpful? Give feedback.
-
A comment from @ctgraham on the benefits of moving (some) config settings to the database:
|
Beta Was this translation helpful? Give feedback.
-
My preferred approach is to use a layered system that allows a sys admin to override user-configurable settings. This would allow a sys admin to "lock down" settings when they want and open them up when they want. Example: $timezone = Config::get('time_zone', 'UTC'); This would return the first value found in the following order:
|
Beta Was this translation helpful? Give feedback.
-
@ctgraham I'd also be interested to know which of the config values you think ought to be site or context settings. Moving these into settings would probably not be too difficult in most cases, and our config file is long overdue for a clean-up. |
Beta Was this translation helpful? Give feedback.
-
This isssue was discussed as a group work in the PKP Sprint 2022 in Helsinki. Here is a summary of the outcomings of the groupwork. Requirement analysis
Expert discussions and issue comments Tom Granroth, The Federation of Finnish Learned Societies Nate Wright, Public Knowledge Project Antti-Jussi Nygård, The Federation of Finnish Learned Societies Marc Bria, Vitaliy Bezsheiko, Jonas Raoni Soares da Silva Tool suggestions
|
Beta Was this translation helpful? Give feedback.
-
With Jim's revival... I think another direction that could be traveled with this is a simple change to the config file parser that looks to a single value and decides whether to get values from the config.inc.php or a standard PHP value. So, let's say that you could allow for a directive variable (let's say, "DYNAMIC_CONFIG_FILE" at the beginning of the config.inc.php that states an alternative .php file that could be used. The php file would be a true php file and would have variables set there. What the variables are set to and how would be up to the user that implements the OJS site. Use an environment variable, directly configure by using a string... however you do it... your call. Just use PHP syntax to set the information. This also allows for the ability to include other php files for differentiated environments as well. I'd say that this only is moderately better than other previous suggestions because it requires minor changes to PKP libs but gets the dynamic capabilities that are sorely needed for dynamic deployment environments. I think this could be quickly implemented while other more elaborate solutions are considered or built. |
Beta Was this translation helpful? Give feedback.
-
If It could be a kind of layered config as previously mentioned. The ini config parser could parse whatever is in the ini file and build up an initial |
Beta Was this translation helpful? Give feedback.
-
Taking a convention-over-configuration approach, perhaps the presence of And going one step further, |
Beta Was this translation helpful? Give feedback.
-
Perhaps this could be a gateway into other configuration mechanisms. If You want to start the configuration with a common but dynamic base configuration, and then lay static configuration from a series of YAML files, and finally lay another dynamic configuration on top of that, do this: $config->from_php('config-base.php'); // For example, determine a default base_url from hostname
$config->from_yaml('config-ofs.yaml');
$config->from_yaml('config-dev.yaml'); // For example, override base_url for the development environemnt
$config->from_php('config-secrets.php'); // For example, read the DB password out of a docker secrets file Possible other methods might be:
|
Beta Was this translation helpful? Give feedback.
-
Currently our configuration file it is a static file, based at the INI file concept.
This concept works well, but did not allow us to change and mock things easily for testing, or used it with environment variables.
We could use the bullet-proof package vlucas/phpdotenv to handle the .env parsing and setting.
One valid use case for this it is the configuration of OJS dockerized environments.
Beta Was this translation helpful? Give feedback.
All reactions