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

我们在 deploy.mysite.com </ em>下设置了一个Laravel部署网站,用于处理部署 对于众多其他网站。</ p>

我正在尝试部署的另一个网站也是Laravel网站,位于 site2.myothersite.com </ em>下。</ p>

两者都在同一台服务器上。 部署在site2上调用脚本,此部署脚本在 cd </ code>之后运行各种命令到项目目录。 我们使用以下命令更新数据库结构。</ p>

  php artisan migrate --force 
</ code> </ pre>

通常情况下 在项目根目录中直接通过SSH运行,它运行得很好。</ p>

但是当通过部署脚本(使用php exec()</ code>运行时) 运行这些命令)该过程确实有效 - 但是,而不是更新我们 cd </ code>'的项目,它会更新部署站点的数据库结构!</ strong> < / p>

似乎 php artisan migrate </ code>命令忽略了我 cd </ code>'d进入另一个项目的事实并且它需要数据库 来自当前目录的值。</ p>

如何更改此行为?</ p>
</ div>

展开原文

原文

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个回答



在玩了多个不同的解决方案后,我终于意识到问题是 .env </ code>文件来自 我所在的项目是设置环境变量,然后没有被任何东西覆盖,因此基本上将代码作为错误的站点运行。</ p>

我做了什么 解决这个问题</ strong> </ p>

在我的部署脚本中,我手动加载 .env </ code>文件并用 overload </ code>覆盖环境变量 而不仅仅是加载</ code>; </ p>

  $ dotenv = Dotenv :: create(__ DIR __); 
$ dotenv-&gt; overload();
</ code> </ pre>

这实际上就是让我的原始脚本工作所必须做的一切。</ p>

注意:</ strong> 因为这是一个完整的laravel安装,已经安装了 dotenv 软件包。 这可以通过单独安装来用于任何项目。</ p>
</ div>

展开原文

原文

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.



您可以将命令更改为与此类似的命令,而不是 cd </ code>:</ p >

php / var / www / sitea / artisan migrate --force </ code> </ p>

这将为提供的目录运行artisan命令。 </ p>
</ div>

展开原文

原文

Rather than cd to the directory, you could change the command to something similar to this:

php /var/www/sitea/artisan migrate --force

That will run the artisan command for the provided directory.

dongyi2083
dongyi2083 您是否检查过以确保站点中的.env文件包含正确的数据库凭据?
大约 2 年之前 回复
dpb42021
dpb42021 这是我实际尝试过的东西 - 我刚刚对它进行了双重检查,不幸的是我得到了相同的结果。 我首先擦除了数据库,而不是创建表,它失败了,告诉我用户表已经存在(它在部署站点上执行),所以即使运行上面的命令,它仍然试图在不同的地方运行它 安装。
大约 2 年之前 回复



  $ log = shell_exec(“unset DB_HOST&amp;&amp; 
unset DB_PORT&amp;&amp;
unset DB_PASSWORD&amp; ;&amp;
取消设置DB_USERNAME&amp;&amp;
取消设置DB_DATABASE&amp;&amp;
composer dump-autoload&amp;&amp;
cd / var / www / yourproject /& amp;&amp; php / var / www / yourproject / artisan migrate:fresh&amp;&amp;
php / var / www / yourproject / artisan db:seed&amp;&amp;
php / var / www / yourproject / artisan seed:translation“);
</ code> </ pre>
</ div>

展开原文

原文

$log = shell_exec("unset DB_HOST &&
       unset DB_PORT && 
       unset DB_PASSWORD && 
       unset DB_USERNAME && 
       unset DB_DATABASE && 
       composer dump-autoload &&
       cd /var/www/yourproject/ && php /var/www/yourproject/artisan migrate:fresh &&
       php /var/www/yourproject/artisan db:seed &&
       php /var/www/yourproject/artisan seed:translation");

立即提问
相关内容推荐