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

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

问题描述

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

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/

当我推送它并在 Heroku 上运行它时,我收到错误消息,抱怨找不到某些文件.奇怪的是,我的 Heroku 应用程序有一个 bash 终端,我可以验证该文件确实在那里!Heroku 不喜欢'../../' 来改变目录吗?

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

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

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

$config = yiihelpersArrayHelper::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')
);

如果它与 '../../' 改变目录有关,那么我认为第一个 require 会出错(对于 main.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).

在 Heroku 上运行 Yii2 高级版时我缺少什么?

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

更新 - 我创建了一个新的 Yii2 基本应用程序.应该工作并且简单,所以我想.显然,即使是基本的应用程序也不能在 Heroku 上运行.文档中必须有一些遗漏,某处......使用作曲家安装 Yii2 basic,将其放在 git 下,将其推送到新的 heroku 堆栈.去看看我在 heroku 上的应用程序,将/web/index.php 添加到 url 的末尾.

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 yiidebugModule does not exist

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

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.

如果没有一些神奇的(和未记录的)技巧,似乎 Yii2 和 Heroku 不能很好地发挥作用.我已经搜索了,搜索了,搜索了,但我找不到任何关于此的信息.我不可能是唯一一个试图在 Heroku 上安装 Yii 应用的人.

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.

所以我尝试了 CloudControl.我将我的股票 Yii2 基本应用程序部署到 cloudcontrol,我再次收到关于根 index.php 的 phpinfo 报告.导航到/web/index.php 并获取错误:

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 – yiiaseInvalidParamException
The file or directory to be published does not exist: /srv/www/code/vendor/bower/jquery/dist

什么给!我可以在本地运行它就好了.当我将它推送到基于云的主机(Heroku 或 CloudControl)时,它失败了!我认为 yiibasic 应用程序最好至少让它为 PoC 运行,但 Yii 开箱即用,不会在这两个服务中运行.有某事没有提到我遗漏了.

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.

推荐答案

终于在折腾了几个小时之后,我想通了.好吧,我还有一个问题需要测试(然后再试一次).然而,我设法让 yii basic 和 yii advanced 应用程序在 Heroku 上运行.尽管如此,CloundControl 仍然有错误,但那是另一天.

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.

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

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": "*"

composer 资产插件是绝对需要的.联系我们页面需要 GD 扩展名(我假设是验证码).我还注释掉了 web/index.php 中 YII_DEBUG 定义的前两行.一旦我这样做了,更新了作曲家,更新了 git 并推送,奇迹就发生了 :)

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

我不认为他们会通知您您需要编辑 web/index.php 以在 Yii2 文档中删除它们.似乎他们只对让您进行开发感兴趣.是的,索引文件有注释,但我们需要知道在那里查看!如果你不删除它们,Yii 将加载你不存在的调试工具.我假设当 Heroku 收到推送时,它会从require"块运行 composer.

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.

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

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.

我想知道 'frontend/web/index.php' 怎么不在目录中,但进一步检查我看到许多目录都有 gitignore 文件.因此,当您git push heroku master"、frontend/web/index.php"以及其他内容时,永远不要因为它们被忽略而被推送.因此,因为我无法让 Heroku 将 Yii 的 init 运行到生产环境中,所以我的文件不存在.

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.

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

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

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

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.

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

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天全站免登陆