Greetings Just started to learn and apply phing . For example, automate the deployment of the project yii2-app-advanced on localhost. It was possible to automate the creation of a local domain, project, definition of dependencies, the creation of the environment, database. Further in the plans - the migration of users and RBAC , but before that you need to add configuration - at least a database. And, most likely, there will be a few more reasons to get into the project scripts automatically. Are there any specials? Tasks for such purposes, and in general, what are the practical recommendations for such tasks?

    1 answer 1

    I do not know if this is relevant for you, but: The database is configured like this:

     <target name="database" description="Configure database"> <echo>Configure database connect</echo> <input propertyname="hostname" defaultValue="127.0.0.1" promptChar="?">Enter hostname of db:</input> <input propertyname="database" defaultValue="" promptChar="?">Enter name of db:</input> <input propertyname="username" defaultValue="" promptChar="?">Enter username to access db:</input> <input propertyname="password" defaultValue="" promptChar="?">Enter password to access db:</input> <input propertyname="prefix" defaultValue="" promptChar="?">Enter table prefix:</input> <copy file="config/db.php.dist" tofile="config/db.php" overwrite="true"> <filterchain> <replacetokens begintoken="[[" endtoken="]]"> <token key="hostname" value="${hostname}" /> <token key="database" value="${database}" /> <token key="username" value="${username}" /> <token key="password" value="${password}" /> <token key="prefix" value="${prefix}" /> </replacetokens> </filterchain> </copy> </target> 

    The database configuration template file looks like this:

     <?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=[[hostname]];dbname=[[database]]', 'username' => '[[username]]', 'password' => '[[password]]', 'charset' => 'utf8', 'tablePrefix' => '[[prefix]]' ];