为什么我部署的 Symfony 应用程序无法加载 bundles.php 文件?

我有一个 Symfony Web 应用程序。我想将其部署到虚拟专用服务器。

我在 Laravel Homestead Vagrant box 中开发了该应用程序,并且我 39;我正在通过 Github 操作进行部署。

在我的本地计算机上,该应用程序在 Vagrant 环境中运行良好,但在将文件同步到实时服务器后,它给我一个错误屏幕。

警告:需要(/var/www/thebedechkacase.com/src/config/bundles.php): 无法打开流:没有这样的文件或目录

错误来自 Kernel.php 的第 20 行,如下所示

const CONFIG_EXTS = '.{php,xml,yaml,yml}';

public function registerBundles()

{

    $contents = require $this->getProjectDir().'/config/bundles.php';

    foreach ($contents as $class => $envs) {

        if ($envs[$this->environment] ?? $envs['all'] ?? false) {

            yield new $class();

        }

}

我不明白的是,根据错误消息和上面的代码,$this->getProjectDir()的输出解析为/var/www/thebedechkacase.com/src/ (< /span>。 实际上位于 thebedechkacase.com 是存储我的应用程序代码的文件夹),但 bundles.php/var/www/thebedechkacase.com/config/

为什么 Symfony 认为 projectDir 位于 src 中,而为什么它不查找 config在根目录中(又名 thebedechkacase.com/)?为什么这在我的开发环境中有效,但在实时服务器上却不起作用?

其他信息: 我正在尝试使用我在 Github 操作中调用的 shell 脚本设置必要的环境变量,但是当我检查时在实时服务器的 shell 上手动设置环境变量,我发现它们都没有设置,所以我的脚本可能首先就被破坏了(这就是为什么你能够看到默认值Symfony 错误页面)。这可能与此有关,或者这是另一个错误?

您可以在其中看到错误的网址: https://thebedechkacase.com/

项目的 Github 存储库: https://github.com/Cooty/the-bedechka-case

部署代码的操作: https://github.com/Cooty/the-bedechka-case/blob/develop/.github/workflows/main.yml< /span>

Symfony 版本: 5.0

实时服务器运行 Ubuntu 20.04、Ngingx、PHP-FPM 7.4 和 PHP 7.4。



有只小跳蛙
浏览 60回答 2
2回答

函数式编程

我从 rsync 命令的文件列表中排除了composer.json,我认为它只需要安装依赖项,但并不是 Symfony 也在运行时读取它。

MMTTMM

Symfony 将“项目目录”设置为基于“composer.json”文件位置。 “项目目录”需要引导应用程序(Web 和 cli)。这就是为什么当您在没有“composer.json”的情况下部署应用程序时,例如。对于 Elasticbeanstalk,您需要像这样修改内核:use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;use Symfony\Component\HttpKernel\Kernel as BaseKernel;class Kernel extends BaseKernel{&nbsp; &nbsp; use MicroKernelTrait;&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* NOTICE:&nbsp; &nbsp; &nbsp;* We don't want to deploy composer.json that's being used to compute project dir, so we will specify it here manually.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; public function getProjectDir()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return \dirname(__DIR__);&nbsp; &nbsp; }注意被重写的 getProjectDir() 方法。
打开App,查看更多内容
随时随地看视频慕课网APP