在Heroku上设置Yii2 Advanced [英] Setup Yii2 Advanced on Heroku

查看:212
本文介绍了在Heroku上设置Yii2 Advanced的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助在Heroku上设置Yii2高级应用程序。我已经使用Composer在本地安装了Yii,完全按照他们的指导: http ://www.yiiframework.com/doc-2.0/guide-tutorial-advanced-app.html



我的网站在本地运行,前端和后端:

  http:// localhost / yii2app / frontend / web / 
http:// localhost / yii2app / backend / web /

当我在Heroku上推送并运行它时,一些文件没有找到。奇怪的是,在我的Heroku应用程序中有一个bash终端,我可以验证该文件实际上在那里! Heroku不喜欢'../../'改变目录吗?

  PHP致命错误:require():Failed需要打开'/app/frontend/web/../../common/config/main-local.php'
include_path ='。:/ app / .heroku / php / lib / php')in /第12行的app / frontend / web / index.php

在'frontend / web / index.php '是Yii的股票代码(第12行是main-local.php):

  $ config = yii\helpers\ArrayHelper :: merge(
require(__ DIR__。'/../../common/config/main.php'),
require(__ DIR__。'/../../common/config/ $ _ $ b require(__ DIR__。'/../config/main.php'),
require(__ DIR__。'/../config/main-local.php' )
);

如果必须使用'../../'来更改目录,那么我会认为第一个要求会有错误(对于main.php条目)。



我错过了什么让Yii2在Heroku上高级运行?



更新 - 我创建了一个新的Yii2基本应用程序。应该工作和简单,所以我想。显然,即使基本的应用程序不能在Heroku上运行。必须从文档中删除某些内容,在某处...使用composer来安装Yii2基本版,将其放在git下,并将其推送到新的heroku堆栈。试图在heroku上查看我的应用程序,将/web/index.php添加到url的末尾。

  ReflectionException 
class yii\debug\Module does not exist

然后我把index.php放在包含phpinfo()的根目录。我可以确认我收到了phpinfo报告。所以PHP正在运行,它报告PHP 5.6.5。



似乎Yii2和Heroku在没有一些神奇(和未记录)技巧的情况下运行得不好。我已经搜索,搜索和搜索,但我无法找到任何关于此的信息。我不可能是唯一一个试图将Yii应用程序加入Heroku的人。



所以我尝试了CloudControl。我将我们的股票Yii2基本应用程序部署到云控制,我再次获得有关根index.php的phpinfo报告。导航到/web/index.php并得到错误:

 参数无效 -  yii\base\InvalidParamException 
要发布的文件或目录不存在:/ srv / www / code / vendor / bower / jquery / dist

什么给!我可以在本地运行这个很好。当我将它推送到基于云的主机(Heroku或CloudControl)时,它会失败!我认为yiibasic应用程序至少可以让它运行在PoC上,但Yii开箱即可,不会在任何一种服务上运行。 没有提到我缺少。

最后几小时和几小时的混乱, 我想到了。那么,我还有一个问题需要测试(并再试一次)。不过,我设法同时运行了Heroku上运行的yii basic和yii高级应用程序。尽管如此,CloundControl仍然存在错误,但那是另一天。



我的composer.json文件中缺少2个条目。我不知道为什么这些没有包含在Yii文档中,如果它们在生产中需要的话。这是我的require块(我不需要编辑require-dev部分,只需要):

 fxp / composer -asset-plugin:*,
ext-gd:*

作曲家资产插件是绝对必需的。 GD扩展需要联系我们页面(我假设验证码)。我还在web / index.php中为YII_DEBUG定义了前两行。一旦我这样做,更新的作曲家,更新的git,并推动,魔术发生:)

我不认为他们通知你,你需要编辑网页/索引。 php在Yii2文档中删除它们。看起来他们只是想让你去发展。是的索引文件有评论,但我们需要知道要看看!如果你不删除它们,Yii会加载你不存在的调试工具。我假设当Heroku收到推送时,它会从require块中运行作曲家。



至于高级模板,前端和后端index.php文件已经有了调试常量用于开发和生产。你只需要在服务器上运行 php init --env = Production --overwrite = All (我无法让heroku做到这一点,但有一天)。 Yii文档让你运行init,然后选择开发。这将采取环境/ dev文件夹中的所有内容,并将它们覆盖在应用程序的位置中。这在开发时会失败。所以你必须将它切换到生产,这会将生产文件转移到使用中。我明白你为什么要这些,所以我明白了。就像我说的,我试过 heroku run bash ,然后运行 php init --env =生产 - 覆盖=所有从apps目录,但它似乎没有使交换机。所以我的应用程序缺少前端/web/index.php文件等等。



我想知道'frontend / web / index.php'如何不是即使在目录中,但进一步检查,我看到许多目录有gitignore文件。所以当你'推动heroku主','frontend / web / index.php'以及其他的时候,永远不要推,因为它们被忽略。所以,因为我无法使用Heroku来运行Yii的init,我的文件就不存在了。



简单修复让我可以在Yii Advanced上运行Heroku(包括将2个提到的软件包添加到composer.json中):我删除了所有gitignore文件,运行init选择生产,更新git,然后推送到heroku。它运行:)

现在我需要弄清楚如何让init为我做这件事,所以我不必删除gitignore文件。



至于这个问题,它已经解决了。 Heroku可以运行Yii2基础版和高级版。我看到的最大的问题是Yii文档缺乏必要的作曲家软件包在生产中运行。所以我想知道Heroku是否需要这些软件包......


I am needing some help setting up a Yii2 Advanced Application on Heroku. I have already installed Yii locally using Composer, following their guide exactly: http://www.yiiframework.com/doc-2.0/guide-tutorial-advanced-app.html

My website works as it should locally, with frontend and backend:

http://localhost/yii2app/frontend/web/
http://localhost/yii2app/backend/web/

When I push it and run it on Heroku, I get errors complaining that some files are not found. What is weird, is with a bash terminal to my Heroku app, I can verify that the file is in fact there! Is Heroku not liking the '../../' to change directory?

PHP Fatal error:  require(): Failed opening required '/app/frontend/web/../../common/config/main-local.php'  
include_path='.:/app/.heroku/php/lib/php') in /app/frontend/web/index.php on line 12

In 'frontend/web/index.php' is Yii's stock code (line 12 is main-local.php):

$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);

If it had to do with the '../../' to change directory, then I would think the first require would have an error (for the main.php entry).

What am I missing to get Yii2 advanced running on Heroku?

UPDATE - I created a new Yii2 basic app. Should work and be simple, so I thought. Apparently even the basic app does not run on Heroku. There MUST be something left out from the docs, somewhere... Used composer to install Yii2 basic, put it under git, pushed it to a new heroku stack. Went to check out my app on heroku, adding /web/index.php to the end of the url.

ReflectionException
Class yii\debug\Module does not exist

I then put index.php in the root directory containing phpinfo(). I can confirm I get a phpinfo report. So php is running, it reports PHP 5.6.5.

Seems like Yii2 and Heroku do not play well without some magical (and un-documented) tricks. I have searched, and searched, and searched, and I can't find anything about this. I can't possibly be the only one trying to get a Yii app onto Heroku.

So I tried CloudControl. I deployed my stock Yii2 basic app to cloudcontrol, again I get a phpinfo report on the root index.php. Navigate to /web/index.php and get errors:

Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: /srv/www/code/vendor/bower/jquery/dist

What gives! I can run this locally just fine. When I push it to a cloud based host (Heroku or CloudControl) it fails! I figured the yiibasic app would be better to at least get it running for PoC, but Yii out of the box, will not run on either of those services. There is something not mentioned that I am missing.

解决方案

Finally after hours and hours of messing around, I figured it out. Well, I still have one question left that I need to test (and try again). However, I managed to get both the yii basic and yii advanced apps running on Heroku. Still got errors on CloundControl though, but that's for another day.

I was missing 2 entries in my composer.json file. I dunno why these are not included in the Yii documentation if they are required in production. Here is my require block (I did not have to edit the require-dev section, just require):

"fxp/composer-asset-plugin": "*",
"ext-gd": "*"

The composer asset plugin was absolutely required. The GD extension is needed for the contact us page (I assume the captcha). I also commented out the first 2 lines in web/index.php for the YII_DEBUG defines. Once I did that, updated composer, updated git, and pushed, magic happened :)

I don't think they inform you that you need to edit web/index.php to remove them in the Yii2 docs. Seems they are only interested in getting you going for development. Yes the index file has comments, but we need to know to look there! If you don't remove them, Yii will load your debug tools, which don't exist. I assume when Heroku receives the push, it runs composer from the "require" block.

As for the Advanced template.. Frontend and Backend index.php files already have the debugging constants correct for dev and production. You just have to run php init --env=Production --overwrite=All on the server (I couldn't get heroku to do this, but another day). The Yii docs have you run init, then select development. This takes everything from the "environments/dev" folder and overwrite them in their locations in your app. This will fail when in development. So you have to switch it to production, which moves your production files into use. I understand why you would have these, so I get it.. Like I said, I tried heroku run bash, then running php init --env=Production --overwrite=All from the apps directory but it didn't seem to make the switch. So my app was missing the frontend/web/index.php file, and many more.

I was wondering how 'frontend/web/index.php' wasn't even in the directory, but further inspection I saw that many directories have gitignore files. So when you 'git push heroku master', 'frontend/web/index.php' along with the rest, never get pushed because they are ignored. So because I couldn't get Heroku to run Yii's init into production, my files just were not there.

Simple fix to get me running on Heroku with Yii Advanced (including adding the 2 mentioned packages to composer.json): I deleted all the gitignore files, ran init choosing production, updated git, and pushed to heroku. It runs :)

Now I need to figure out how to get init to do this for me so I don't have to delete the gitignore files.

As for this question, it is solved. Heroku can run Yii2 basic and advanced. The biggest issue I see is the Yii docs lacking the necessary composer packages to run in production. So I wonder if it's just Heroku needing those packages...

这篇关于在Heroku上设置Yii2 Advanced的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆