简体   繁体   English

为什么Heroku找不到我的autoload.php文件?

[英]Why can't Heroku find my autoload.php file?

I'm setting up a demo site for a Wordpress plugin on Heroku. 我正在Heroku上为Wordpress插件设置一个演示站点。 My plugin uses composer to manage dependencies, and it's configured as a git submodule on my local installation. 我的插件使用composer来管理依赖项,它在我的本地安装上配置为git子模块。 I push to heroku and everything seems to work. 我推送到heroku,一切似乎都有效。 I use heroku run bash to ssh into the app and manually run composer install from inside my plugin. 我使用heroku run bash ssh进入应用程序并从我的插件中手动运行composer install Then I log into the site and try to activate my plugin... but I get the following error: 然后我登录该网站并尝试激活我的插件...但我收到以下错误:

Plugin could not be activated because it triggered a fatal error.

Warning: require_once(/app/wp-content/plugins/wp-github-pipeline/vendor/autoload.php): failed to open stream: No such file or directory in /app/wp-content/plugins/wp-github-pipeline/wp-github-pipeline.php on line 23 Fatal error: require_once(): Failed opening required '/app/wp-content/plugins/wp-github-pipeline/vendor/autoload.php' (include_path='.:/app/.heroku/php/lib/php') in /app/wp-content/plugins/wp-github-pipeline/wp-github-pipeline.php on line 23

I don't get it. 我不明白。 With heroku run bash I can see that the file is actually there. 使用heroku run bash我可以看到该文件实际上存在。 And I don't get this issue locally or on another remote server. 我在本地或其他远程服务器上没有遇到此问题。 Why is it happening here? 为什么会在这里发生?

在此输入图像描述

在此输入图像描述

I can't say for sure why this worked but it appears that Heroku doesn't really play nicely with composer.json somewhere other than the project root. 我不能肯定地说为什么这样可行但是看起来Heroku并没有真正与composer.json在项目根目录之外的某个地方很好地协作。 So I took my project's composer.json and moved it to the project root, then I added... 所以我拿了我的项目的composer.json并将它移动到项目根目录,然后我添加了......

"config": {
    "vendor-dir": "wp-content/plugins/wp-github-pipeline/vendor"
}

...which caused the dependancies I needed (and the autoload.php) to get installed in the original location. ...导致我需要的依赖(和autoload.php)安装在原始位置。

With this, I am able to push to Heroku normally without issues. 有了这个,我能够毫无问题地推送到Heroku。

I have NO idea why I was able to run composer install manually without it working. 我不知道为什么我能够在没有它工作的情况下手动运行composer install I also have NO idea why heroku run bash would show me files that aren't actually there. 我也不知道为什么heroku run bash会显示我实际上并不存在的文件。

According to me you have to regenerate the autoload. 据我说,你必须重新生成自动加载。 Hope that you have written code within composer.json for autoloads. 希望你在composer.json中为autoloads编写代码。

composer dump-autoload

This will regenerate your autoload and it will solve your problem. 这将重新生成您的自动加载,它将解决您的问题。 If not please modify your question by pasting your composer.json. 如果没有,请通过粘贴composer.json来修改您的问题。

What I did to solve this was add an include_path to my .user.ini file. 我解决这个问题的方法是在我的.user.ini文件中添加一个include_path That ini file needs to be located in the document root , not the app's root. 该ini文件需要位于文档根目录中 ,而不是应用程序的根目录中。

include_path = ".:/app/.heroku/php/lib/php:/app/vendor/" include_path =“。:/ app / .heroku / php / lib / php:/ app / vendor /”

Don't copy my include_path example verbatim, as it might now be the needed include path for your app. 不要逐字复制我的include_path示例,因为它现在可能是您的应用所需的包含路径。 Get your current include path from Heroku's error log, and then append :/app/vendor to it. 从Heroku的错误日志中获取您当前的包含路径,然后将:/app/vendor附加到它。

What's important there is adding /app/vendor/ to the include_path. 重要的是添加/app/vendor/到include_path。 That will point your require php statement to the spot where Heroku puts the autoload.php . 这将指向你的require php语句到Heroku放置autoload.php

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

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