據我了解,如果您composer.json在根目錄中包含一個文件并且不包含供應商文件,那么 Composer 將自動處理 JSON 指令中的庫。該composer.json文件是 PHPMailer Github 上當前的 51 行 json 文件,它位于我的 EB 根文件夾中,其中包含/public和.ebextensions然后我有這個 PHP 腳本 ( public/phphead.php),從 AWS 文檔復制// Import PHPMailer classes into the global namespace// These must be at the top of your script, not inside a functionuse 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 logEB 的錯誤日志輸出:PHP 致命錯誤:未捕獲的錯誤:在 /var/app/current/public/phpHead.php:64\n 堆棧跟蹤中找不到類 'PHPMailer\PHPMailer\PHPMailer':\n#0 /var/app/current/public/index .php(3): include()\n#1 {main}\n 在第 64 行的 /var/app/current/public/phpHead.php 中拋出我composer.json正在使用(與 PHPMailer 的composer.json文件相同,取自 GitHub):{ "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" },
1 回答

蠱毒傳說
TA貢獻1895條經驗 獲得超3個贊
我沒有使用過 EB,但基于您認為它會composer install在需要時運行的假設,您需要包含一個有效的composer.json.
您包括包的composer.json。因此,您正在安裝 PHPMailer 的依賴項,而不是 PHPMailer 本身。
您需要為您的項目/應用程序創建自己的composer.json文件,在其中聲明 PHPMailer 為您的應用程序的依賴項。
例如:
{
"name": "your/app",
"type": "project",
"description": "",
"license": "CC-0",
"require": {
"phpmailer/phpmailer": "~6.1"
}
}
在任何情況下,您都應該離線嘗試您的代碼(包括原始依賴項安裝),然后再將其上傳到 EB。
如果您嘗試composer install離線運行和運行項目,您會遇到同樣的問題。在部署之前運行您的基本項目。
- 1 回答
- 0 關注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消