Hello, I encountered the following problem: it is necessary to work with a project on a local server, and after tests, upload to the database without changes to the database, etc. Tell me how to do this? Those. I have localhost, of course, localhost , and on a host, for example tret44566 and when tret44566 to production, it constantly needs to be changed.

    1 answer 1

    Usually, two or more environments are entered at the application level, depending on which server the application is on, it selects a set of settings on its own. As a rule, this is implemented through environment variables, for example, you can create the environment variable APP_HOST .

    nginx

     location ~ \.php$ { ... fastcgi_param APP_HOST prod; ... } 

    apache

     <VirtualHost hostname:80> ... SetEnv APP_HOST prod ... </VirtualHost> 

    In the application, you can read the environment variable and depending on what value it is set to assign one or another set of parameters (the getenv() function is used for this, which can have its own wrappers in different languages, you should specify for each language). Using environment variables, you can set critical information, such as passwords, so that they are not present in the code and never leave the server for which they are intended.