dpnhp20440 2018-10-15 10:59
浏览 86
已采纳

从一个Laravel安装到另一个运行php artisan

We have a Laravel deployment website set up under deploy.mysite.com which handles deployments for a multitude of other websites.

One other website I'm trying to deploy which is also a Laravel site resides under site2.myothersite.com.

Both are on the same server. Deploy calls a script on site2, this deploy script runs various commands after cd'ing to the project directory. We use the following to update the database structure.

php artisan migrate --force

Ordinarily when this is run directly via SSH when in the project root, it runs just fine.

However when this is run via the deployment script (using php exec() to run these commands) the process does work - however, instead of updating the project that we've cd'd into, it updates the database structure of the deployment site!

It seems as if the php artisan migrate command ignores the fact I've cd'd into another project and it takes the database values from the current directory.

How can I go about changing this behaviour?

  • 写回答

3条回答 默认 最新

  • dtxa49711 2018-10-19 09:18
    关注

    After playing around with multiple different solutions I eventually came to realise that the problem was the .env file from the project that I was in was setting the environment variables and then weren't being overwritten by anything therefore was then essentially running the code as the wrong site.

    What I did to solve this

    In my deploy script I manually loaded up the .env file and overwrote the environment variables with overload rather than just load;

    $dotenv = Dotenv::create(__DIR__);
    $dotenv->overload();
    

    This was literally all I had to do to get my original script working.

    NOTE: as this is a laravel install at all ends, the dotenv package was already installed. This could be used for any project by installing it separately.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?