Search code examples
phpdatabaseconsoleyii2migrate

How run migrate commands by controller?


I want create an installation controller for my web app and for config db need run migration commands from controller.

For example when user visit

localhost/backend/webapp/index.php?install/step1

by action step1 run migrate up and down command and do installation.


Solution

  • Thanks from @soju and @meysam you can use both solutions.

    1. Use exec:

    Perhaps combining stackoverflow.com/a/35864018/1592247 and exec function of php could helps (@meysam)

    1. Use extensions:

    How can I call a console command in web application in Yii 2.0 (@soju)

    Both way may help you. be aware using exec may cause some security issues and disable in some servers.