Entering database settings from application.ini and into the environment

In traditional Zend-based application coding, database parameters are stored in application.ini. This saves the settings for each application.

Has anyone here at StackOverflow explored the ability to move database settings from application.ini to the environment? For example, the main way would be to save, perhaps, the database connection settings in the envvars Apache2 file, or perhaps something like / etc / profile or / etc / environment.

There are several reasons why I would like to do this:

1) There is a security risk when you have live production database settings in the application. Developers may inadvertently connect to the database in real time and damage the clientโ€™s confidential data. This will protect both developers and end users.

2) It is difficult to maintain and manage db settings for multiple applications. For example, if the username or password is changed for the database, we will need to change application.ini or several applications, which would mean deploying the entire file or the entire application again.

3) An application can be deployed to mark up โ€œproductionโ€ environments where database settings vary. Therefore, there may be several sections in application.ini - for example, and production-datacentreX, production-datacentreY.

As you can see, there is an argument about saving the database settings on the server side. Therefore, it might be better to have database parameters outside the application in the global scope for all applications to access? It would be its own source control, perhaps it would not be available to developers.

What do you think? Has anyone done something like this? I like the idea of โ€‹โ€‹a global application.ini application (perhaps called database.ini?)

Looking forward to hearing answers to this question.

Hello,

Steve

+4
source share
1 answer

In my last project, I did something similar. I have application.ini , which is stored in the repository and contains general settings for the application (viewing options, helpers path, enable layout and the like). But each application instance (each developer has one of them + a testing and development server) has its own local.ini file (which is not supported by versions) with database settings and development directives (including FirePHP, ZFDebug). Thanks to this solution, we can make changes "globally" - application.ini, and each developer can change the settings "locally" - using the local.ini file.

In Bootstrap.php I merge them as shown below:

 protected function _initLocalConfig() { $globalConfig = new Zend_Config($this->getOptions(), true); try { $localConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/local.ini'); $globalConfig->merge($localConfig); $this->setOptions($globalConfig->toArray()); } catch (Zend_Config_Exception $e) { throw new Exception('File /configs/local.ini not found. Create it, it can be empty.'); } } 

I am using a second static file named .ini here, in another project we are using .ini files based on hostnames. They can also be JSON, XML or YAML files (for using the built-in Zend_Config parsers), or you can write your own adapter.

As you can see, you can use your usual configuration from almost anywhere you want :)

+5
source

Source: https://habr.com/ru/post/1340447/


All Articles