首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP类在弹性豆柄中未被识别

PHP类在弹性豆柄中未被识别
EN

Stack Overflow用户
提问于 2020-03-02 01:05:28
回答 1查看 208关注 0票数 1

正如我所理解的,如果您在根目录中包含一个composer.json文件,并且不包含供应商文件,那么composer将自动处理JSON指令中的库。

composer.json文件与当前PHPMailer Github上的51行json文件相同,它位于我的EB根文件夹中,其中有/public.ebextensions

然后我有了这个PHP脚本(public/phphead.php),它是从AWS复制的。

代码语言:javascript
复制
// Import PHPMailer classes into the global namespace

// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require '../vendor/autoload.php';

// requiring /vendor/autoload.php would throw a fatal error and so I presume this is where composer creates the vendor dir. no more fatal errors have been thrown and I have been looking to confirm this is the right location but I have only the lack of errors to make me think composer is found and working...
// ....
$mail = new PHPMailer(); //LINE 64 as per error log

来自EB的错误日志输出:

PHPMailer\PHPMailer:在/var/app/

/public/phpHead.php: 64 \nStack trace:\n#0 /var/app/current/public/index.php(3):在/var/app/current/phpHead.php行中抛出的/var/app/phpHead.php中包含()\n#1 {main}\n

我使用的composer.json (与PHPMailer的composer.json文件相同,取自GitHub):

{“名称”:"phpmailer/phpmailer“、"type":”库“、"description":"PHPMailer是一个功能齐全的用于PHP的电子邮件创建和传输类”,"authors":{ "name":"Marcus Bointon"," email ":"phpmailer@synchromedia.co.uk“},{“名称”:“Jagielski”、“电子邮件”:"jimjag@gmail.com“}、{”名称“:"Andy”、“电子邮件”:"codeworxtech@users.sourceforge.net“},{ "name":“brentR.matzelle”},"require":{ "php":">=5.5.0","ext-ctype":"*","ext-filter":"*“},”require“:{ "friendsofphp/php-cs-fixer":"^2.2","phpunit/phpunit":"^4.8平行^5.7",“原则/注释”:"^1.2“},”建议“:{ "psr/log":”用于可选的PSR-3调试日志“,”联赛/OAuth2-Google“:”谷歌XOAUTH2身份验证所需“,"hayageek/oauth2-yahoo":”雅虎XOAUTH2身份验证所需“,"stevenmaguire/oauth2-microsoft":“Microsoft XOAUTH2身份验证所需”、"ext- Mbstring ":“需要以多字节编码字符集发送电子邮件”、“symfony/poly填充-Mbstring”:“如果未启用Mbstring扩展插件,则支持UTF-8”},"autoload":{ "psr-4":{“PHPMailer\”:"src/“},”autoload dev“:{ "psr-4":{ "PHPMailer\Test\":"test/”},“许可”:“LGPL-2.1-仅”} }

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-02 08:44:51

我没有使用EB,但是根据您的假设,在需要时它将运行composer install,您需要包含一个有效的composer.json

您正在包括包的 composer.json。因此,您正在安装PHPMailer的依赖项,而不是PHPMailer本身。

您需要为您的项目/应用程序创建自己的composer.json文件,在该文件中,您将PHPMailer声明为应用程序的依赖项。

例如:

代码语言:javascript
复制
{
  "name": "your/app",
  "type": "project",
  "description": "",
  "license": "CC-0",
  "require": {
    "phpmailer/phpmailer": "~6.1"
    }
}

无论如何,在将代码上传到EB之前,您应该尝试您的代码(包括原始依赖项安装)脱机

如果您尝试运行composer install并脱机运行您的项目,您就会遇到同样的问题。让您的基本项目在部署之前运行

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60481312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档