简体   繁体   English

在Bluemix上部署Symfony2

[英]Deploying Symfony2 on Bluemix

We are trying to deploy a symfony2 application on bluemix, without success... We have seen a few posts about this kind of issue, but they are either without answer, or obsoletes, or with a slightly different issue. 我们正在尝试在bluemix上部署symfony2应用程序,但没有成功...我们已经看到了有关此类问题的几篇文章,但是它们要么没有答案,要么已过时,或者存在稍微不同的问题。

We have a symfony application, based on the symfony standard edition distribution, moved in a backend folder because we also have a frontend. 我们有一个基于symfony标准版发行版的symfony应用程序,因为它也有一个前端,所以将其移动到后端文件夹中。 However, the composer.json is in the root directory, and references the backend folder. 但是,composer.json在根目录中,并且引用了后端文件夹。 This is the only modification done. 这是唯一完成的修改。

Everything works fine locally, but not on Bluemix with the PHP buildpack, here is the error : 一切在本地都可以正常运行,但是在带有PHP buildpack的Bluemix上却不能,这是错误:

Generating autoload files

  [RuntimeException]                                                                                             
  Could not scan for classes inside "backend/app/AppKernel.php" which does not appear to be a file nor a folder  

On Bluemix the env is set to prod through the manifest.yml , and we have tried the composer install in the same configuration locally: 在Bluemix上,env通过manifest.yml设置为prod,我们尝试在本地以相同配置安装composer:

 applications:
 - name: myapp
   random-route: true
   memory: 128M
   env:
    SYMFONY_ENV: prod
    #BP_DEBUG: true

This error is the one I get with verbose mode, and I have exactly the same without verbose mode. 这个错误是我在详细模式下遇到的错误,而在没有详细模式的情况下我遇到的错误则完全相同。 We run in no-dev mode on Bluemix, here is the full options.json : 我们在Bluemix上以无开发模式运行,这是完整的options.json

{
    "COMPOSER_INSTALL_OPTIONS": [ "--no-dev", "-vvv"]
}

I have attempted to add scripts for debugging purpose. 我试图添加脚本进行调试。 It works well locally but not on Bluemix, so it does not help at all. 它在本地运行良好,但不能在Bluemix上运行,因此完全没有帮助。 Extract from composer.json : composer.json中提取:

"scripts": {
    "pre-autoload-dump": [
        "echo TEST"
    ],
    ...
}

The file exists and is in the right place: 该文件存在且位于正确的位置:

   $ ll backend/app/
    total 128
    drwxr-xr-x 6 bob bob  4096 févr. 28 15:45 .
    drwxr-xr-x 9 bob bob  4096 févr. 28 15:44 ..
    -rwxr-xr-x 1 bob bob   101 févr. 23 11:37 AppCache.php
    -rwxr-xr-x 1 bob bob  1394 févr. 24 11:32 AppKernel.php
    -rwxr-xr-x 1 bob bob   263 févr. 23 11:37 autoload.php
    -rw-r--r-- 1 bob bob 40956 févr. 28 15:45 bootstrap.php.cache
    drwxr-xr-x 3 bob bob  4096 févr. 28 15:45 cache
    -rwxr-xr-x 1 bob bob  3909 févr. 28 15:45 check.php
    drwxr-xr-x 2 bob bob  4096 févr. 28 14:37 config
    -rwxr-xr-x 1 bob bob   897 févr. 22 15:28 console
    -rwxr-xr-x 1 bob bob   143 févr. 23 11:37 .htaccess
    drwxr-xr-x 2 bob bob  4096 févr. 28 14:37 logs
    -rwxr-xr-x 1 bob bob  1358 févr. 23 11:37 phpunit.xml.dist
    drwxr-xr-x 3 bob bob  4096 févr. 23 11:37 Resources
    -rwxr-xr-x 1 bob bob 34272 févr. 28 15:45 SymfonyRequirements.php

It seems like the configuration is correct (looking for the right place) in the composer.json . 看来 composer.json中的配置正确(寻找正确的位置)。 The same file is used locally without any issue: 本地使用同一文件没有任何问题:

"extra": {
        "symfony-app-dir": "backend/app",
        "symfony-web-dir": "backend/web",
        ...
}

Last thing I have in mind is that I did a cf delete myapp before doing a new cf push just to be sure the latest files are taken into account on Bluemix (because I don't understand why the pre-autoload-dump scripts are not run on Bluemix) 我要记住的最后一件事是我在执行新的cf推送之前做了cf删除myapp ,只是为了确保在Bluemix上考虑了最新文件(因为我不明白为什么pre-autoload-dump脚本没有被使用)在Bluemix上运行)

Thanks for the help! 谢谢您的帮助!

I have found the issue. 我发现了问题。

First, I found it by doing this: 首先,我通过执行以下操作找到了它:

I have added the no-script and no-autoloader option to composer, to make sure that the container will run and I'm able to connect to it to see the filesystem. 我在composer中添加了no-script和no-autoloader选项,以确保该容器将运行并且我能够连接到该容器以查看文件系统。 Without that, the container is destroyed and there's no way to know what happened. 否则,容器将被破坏,无法知道发生了什么。

"COMPOSER_INSTALL_OPTIONS_DEBUG": [ "--no-dev", "-vvv", "--no-autoloader", "--no-scripts"]

Then I have connected to the container with ssh (only with Diego): 然后,我已使用ssh连接到容器(仅适用于Diego):

cf enable-ssh
cf ssh

Then, by looking at the filesystem, I found out that the backend and frontend folders are put in an htdocs folder. 然后,通过查看文件系统,我发现后端前端文件夹位于htdocs文件夹中。

I have changed my composer.json to reference htdocs/backend/ instead of just backend/ and everything works fine. 我已经将composer.json更改为引用htdocs / backend /而不是仅backend /,并且一切正常。 Sample from the composer.json file: 来自composer.json文件的样本:

    "autoload": {
        "psr-4": { "": "htdocs/backend/src/" },
        "classmap": [ "htdocs/backend/app/AppKernel.php", "htdocs/backend/app/AppCache.php" ]
    },

The issue now is that I have a different behavior between the local environment (everything is in ./ ) and the container (everything is in htdocs/ ), and composer.json not supporting environment variables makes it complicated to use only one file. 现在的问题是,我在本地环境(一切都在./ )和容器(一切都在htdocs / )之间有不同的行为,并且composer.json不支持环境变量使得仅使用一个文件变得很复杂。 But that's another story. 但这是另一个故事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM