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条)

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题