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.
2) 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?
An important feature of the advanced app is having separate backend and frontend apps. So if you check out your repo to /var/www/myproject
, two important directories will be created: /var/www/myproject/frontend/web
and /var/www/myproject/backend/web
. You usually configure your web server to have these two directories as web roots for two different domains (like example.com
and admin.example.com
).
Yii2 advanced app introduces the concept of "environments". An environment is basically a set of config files, that, among other things, include db credentials. So if you don't mind having credentials in your repo, push-deployment is possible.
So if you plan to have multiple servers with multiple configs, you just create an environment for each server and use it to deploy.
So here are the steps you need to take after checking out the repo.
composer install
Pretty straightforward. Keep in mind that fxp/composer-asset-plugin
needs to be installed globally for composer to fetch bower and npm dependencies.
init --env=your_server_environment --overwrite=All
You should overwrite everything. If you have updated some parameter in your environment, it will be applied to the current setup.
yii migrate --interactive=0
That's all there is to it.