-
Notifications
You must be signed in to change notification settings - Fork 448
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Consider implementing the phpdotenv usage to handle configuration #7068
Comments
As mentioned by @marcbria on Slack:
We could try to implement the phpdotenv at |
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. |
Can you give some code examples showing the limitations you're hitting with the current |
The one that Laravel uses? |
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. |
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? |
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. |
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). |
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. |
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 |
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? |
Another option to consider, which would keep the |
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. |
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. |
A comment from @ctgraham on the benefits of moving (some) config settings to the database:
|
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:
|
@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. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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.
The text was updated successfully, but these errors were encountered: