What's the correct way to init yii2 framework with push-to-deploy

I’ve created post-receive hook for git repository which checkouts commit to web folder /var/www/myproject. Since I’m not committing dependencies (framework files), when checked out I have to install dependencies and init the framework. I see two approaches:

  1. When checked out run the following commands from the project directory:

composer install

php init --env=Development --overwrite=n

#other commands to setup db connection, credentials etc.

  1. Install dependencies one level up of checked out project /var/www and have links one level up. But it seems that with this approach I’ll still need to run php init.

What’s the common approach for such deployment?

There is some docs on this: http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html#deploying-a-basic-application

However, it is scanty. :)

I am not an expert, but I use the advanced template which uses separate web dirs that we can point our server root at.

For the actual deployment, I usually deploy and init a production instance locally and then arhive send and unarchive to the server, with some directories/files excluded.

I don’t want to run any commands on the server (composer/npm/ruby/etc).

Maybe there is an article about this on the wiki?

I should probably write a Python or Nodejs script to automate the deploy, but I am betting my horse that you beat me to that :)

Similar to Jacob above, but I don’t like to run the deploy scripts on a live server. Also, I wanted to replicate my live config on a testing server, so I have setup separate configs for live and dev.




-- protected

    -- config

        -- main-dev.php

        -- main-live.php

        -- main.php



and the same with params also.

Then in my www/index.php I can change the includes depending on YII_ENV





$config = yii\helpers\ArrayHelper::merge(

    require(__DIR__ . '/../_protected/common/config/main.php'),

    require(__DIR__ . '/../_protected/common/config/main-dev.php'),

    require(__DIR__ . '/../_protected/frontend/config/main.php'),

    require(__DIR__ . '/../_protected/frontend/config/main-live.php')

);



I like this as i) there is no risk of over-writing configs on the live server, I can just upload the entire protected directory ii) my testing server will often include main-live but common/main-dev and params-dev

Whether this is the “right” way or not is debatable - it’s more about your server setup and your preference.