Composer 在 elasticbeanstalk 上部署 laravel 应用程序时出错
Posted
技术标签:
【中文标题】Composer 在 elasticbeanstalk 上部署 laravel 应用程序时出错【英文标题】:Composer error deploying laravel application on elasticbeanstalk 【发布时间】:2021-08-13 23:22:54 【问题描述】:我有一个托管在弹性 beanstalk 上的 laravel 应用程序,它还与代码管道连接。当我部署应用程序时,我在 ebs 面板上收到此错误:
错误:在中止部署期间,某些实例可能已部署新的应用程序版本。为确保所有实例都运行相同的版本,请重新部署相应的应用程序版本。
我不知道它是否相关,但是当我下载日志时发现:
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event
returned with error code 1
这是我的 composer.json
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require":
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5"
,
"require-dev":
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
,
"config":
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
,
"extra":
"laravel":
"dont-discover": []
,
"autoload":
"psr-4":
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
,
"autoload-dev":
"psr-4":
"Tests\": "tests/"
,
"minimum-stability": "dev",
"prefer-stable": true,
"scripts":
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
【问题讨论】:
【参考方案1】:看来你有一些错别字。特殊字符“\”必须是“\\”用于文件夹分隔。 试试这个 composer.json:
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require":
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5"
,
"require-dev":
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
,
"config":
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
,
"extra":
"laravel":
"dont-discover": []
,
"autoload":
"psr-4":
"App\\": "app /",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
,
"autoload-dev":
"psr-4":
"Tests\\": "tests/"
,
"minimum-stability": "dev",
"prefer-stable": true,
"scripts":
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
现在作曲家必须能够运行脚本。 Composer 安装必须完成安装,否则会向您提供有关文件的明确警告或错误。
【讨论】:
我的代码确实有特殊字符。但它不在 composer.json 文件中【参考方案2】:所以我只是找出发生了什么!我试图增加我的实例,然后当我下载完整的日志时有新信息:
021/05/25 18:00:11.083949 [INFO] Running command /bin/sh -c composer.phar install --no-ansi --no-interaction
2021/05/25 18:00:18.791014 [INFO]
ParseError
syntax error, unexpected character 0x1D, expecting "]"
at app/Http/Controllers/MailController.php:28
24▕ 'nome' => $request->nome,
25▕ 'email' => $request->email,
26▕ 'assunto' => $request->assunto,
27▕ 'descricao' => $request->descricao,
➜ 28▕ 'local' => $request->localizacao,
29▕ 'pais' => $request->pais
30▕ ]);
31▕
32▕ if($response->status() === 200)
[2m+1 vendor frames [22m
2 [internal]:0
Composer\Autoload\ClassLoader::loadClass("App\Http\Controllers\MailController")
[2m+9 vendor frames [22m
12 routes/web.php:24
Illuminate\Support\Facades\Facade::__callStatic("post")
2021/05/25 18:00:18.791081 [ERROR] An error occurred during execution of command [app-deploy] - [Install composer dependencies]. Stop running the command. Error: installing composer dependencies failed with error: Command /bin/sh -c composer.phar install --no-ansi --no-interaction failed with error exit status 1. Stderr:Do not run Composer as root/super user! See https://getcomposer.org/root for details
我在 vscode 上看不到那些 ascii,但是当我用 sublime 打开项目时,它们就在那里!我猜我的实例内存不足,因此它没有注销太多,当我更改层级时,更多信息被注销。我刚刚删除了那些 ascii,现在它工作得很好。
【讨论】:
以上是关于Composer 在 elasticbeanstalk 上部署 laravel 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章
Composer 在 /var/www/html 中找不到 composer.json 文件
Windows下Composer依赖控制器下载纯净版laravel