据我对Elastic Beanstalk的了解,如果您在根目录中包含composer.json文件,并且不包含供应商文件,那么composer会根据JSON指令自动处理该库。
[composer.json文件是根据PHP Mailer github上当前的51行json文件,它位于我的EB根文件夹中,带有/ public和.ebextensions]
然后此.php页面(/public/phphead.php)如下(最初取自AWS文档)
<?php
// 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的错误日志输出:
PHP致命错误:未捕获的错误:类找不到“ PHPMailer \ PHPMailer \ PHPMailer”/var/app/current/public/phpHead.php:64\n堆栈跟踪:\ n#0/var/app/current/public/index.php(3):include()\ n#1 {main} \ n/var/app/current/public/phpHead.php,第64行
我已经经历了一段时间,经过仔细检查和谷歌搜索,我迫切希望找出正在发生的事情...。我只是无法找出问题所在...
任何帮助将不胜感激!
Addendum composer.json(与github phpmailer相同)
{ "name": "phpmailer/phpmailer", "type": "library", "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "authors": [ { "name": "Marcus Bointon", "email": "[email protected]" }, { "name": "Jim Jagielski", "email": "[email protected]" }, { "name": "Andy Prevost", "email": "[email protected]" }, { "name": "Brent R. Matzelle" } ], "require": { "php": ">=5.5.0", "ext-ctype": "*", "ext-filter": "*" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.2", "phpunit/phpunit": "^4.8 || ^5.7", "doctrine/annotations": "^1.2" }, "suggest": { "psr/log": "For optional PSR-3 debug logging", "league/oauth2-google": "Needed for Google XOAUTH2 authentication", "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", "ext-mbstring": "Needed to send email in multibyte encoding charset", "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" }, "autoload": { "psr-4": { "PHPMailer\\PHPMailer\\": "src/" } }, "autoload-dev": { "psr-4": { "PHPMailer\\Test\\": "test/" } }, "license": "LGPL-2.1-only" }
package's composer.json。因此,您正在安装PHPMailer的依赖项,而不是PHPMailer本身。
您需要为您的项目/应用程序创建自己的composer.json
文件,并在其中向PHPMailer声明应用程序的依赖项。
{
"name": "your/app",
"type": "project",
"description": "",
"license": "CC-0",
"require": {
"phpmailer/phpmailer": "~6.1"
}
}
在任何情况下,在将其上传到EB之前,您都应该尝试将其代码(包括原始依赖项安装)
offline尝试。
如果您尝试运行composer install
并离线运行项目,则可能会遇到相同的问题。让基本项目运行之前部署。