問題描述
為什麼 composer.json 需要 PHP 7.4 但服務器正在運行 PHP 7.3 不會中斷部署? (Why composer.json requires PHP 7.4 but server is running PHP 7.3 doesn't break in deployment?)
我們的服務器正在運行 PHP 7.3,但 composer.json 文件需要 PHP 7.4。我們不小心部署到服務器上,但它沒有中斷。我們想知道這是緩存問題還是其他問題?有人可以在這里分享一些燈嗎?我們想知道哪些潛在部件可以防止服務器崩潰。
我們無法手動運行 composer install or update
來做一些實驗,因為它在生產服務器上。但是,我們嘗試在本地重現,但是當我們運行 composer install
時它總是會中斷。
注意:我們正在使用 Forge 進行部署
這是我們的部署腳本
date
cd /home/forge/default
git pull origin master
composer install ‑‑no‑dev ‑‑prefer‑dist
php artisan migrate ‑‑force
npm install
npm run production
echo “” | sudo ‑S service php7.3‑fpm reload
這是我們的composer.json
{
“name”: “laravel/laravel”,
“type”: “project”,
“description”: “The Laravel Framework.“,
“keywords”: [
“framework”,
“laravel”
],
“license”: “MIT”,
“require”: {
“php”: “^7.4|^8.0",
“algolia/algoliasearch‑client‑php”: “^2.7",
“algolia/scout‑extended”: “^1.10",
“backup‑manager/laravel”: “^2.0",
“ckfinder/ckfinder‑laravel‑package”: “v3.5.1.6",
“cviebrock/eloquent‑sluggable”: “^7.0",
“davejamesmiller/laravel‑breadcrumbs”: “^5.3",
“doctrine/dbal”: “^2.11",
“fideloper/proxy”: “^4.4",
“fruitcake/laravel‑cors”: “^2.0",
“geoip2/geoip2”: “^2.9",
“graham‑campbell/markdown”: “^13.1",
“guzzlehttp/guzzle”: “^6.3.1|^7.0.1",
“intervention/image”: “^2.5",
“jenssegers/agent”: “^2.6",
“jordanmiguel/laravel‑popular”: “^1.0",
“kyslik/column‑sortable”: “^6.3",
“laracasts/presenter”: “^0.2.1",
“laravel/framework”: “^7.29",
“laravel/passport”: “^9.3",
“laravel/scout”: “^8.3",
“laravel/tinker”: “^2.5",
“laravel/ui”: “^2.0",
“laravelcollective/html”: “^6.2",
“laravelium/sitemap”: “^7.0",
“league/flysystem‑aws‑s3‑v3”: “^1.0",
“mtownsend/read‑time”: “^1.1",
“otisz/laravel‑imgix”: “^3.0",
“renatomarinho/laravel‑page‑speed”: “^1.8",
“sentry/sentry‑laravel”: “^2.1",
“spatie/dns”: “^1.4",
“spatie/laravel‑csp”: “^2.6",
“spatie/laravel‑permission”: “^3.17",
“themsaid/forge‑sdk”: “^2.2",
“toin0u/geocoder‑laravel”: “^4.1",
“torann/geoip”: “^1.2",
“tucker‑eric/eloquentfilter”: “^2.3",
“unisharp/laravel‑filemanager”: “dev‑master”
},
“require‑dev”: {
“barryvdh/laravel‑debugbar”: “^3.5”,
“laravel/dusk”: “^6.11”,
“laravel/telescope”: “^3.5”,
“laravel/tinker”: “^2.5”,
“mockery/mockery”: “^1.3.1”,
“nunomaduro/collision”: “^4.3”,
“phpunit/phpunit”: “^8.5.8|^9.3.3”,
“fakerphp/faker”: “^1.9.1”,
“facade/ignition”: “^2.0”
},
“config”: {
“optimize‑autoloader”: true,
“preferred‑install”: “dist”,
“sort‑packages”: true,
“platform”: {
“php”: “7.4”
}
},
“extra”: {
“laravel”: {
“dont‑discover”: [
“laravel/telescope”
]
}
},
“autoload”: {
“psr‑4”: {
“App\\“: “app/“,
“Mpociot\\Versionable\\“: “packages/mpociot/versionable/src/Mpociot/Versionable/“,
“CKSource\\CKFinderBridge\\“: “packages/ckfinder/ckfinder‑laravel‑package/src/“,
“CKSource\\CKFinder\\“: “packages/ckfinder/ckfinder‑laravel‑package/_connector/”
},
“classmap”: [
“database/seeds”,
“database/factories”
]
},
“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:
If you have older viersion of PHP in server it dosn't mean it always break the program. But if Your program or Your dependencies used any new features or any removed features it will break. in here you can see the differences between 7.3 and 7.4
方法 2:
You should use PHP 7.4 if composer.json requires this. If you don't want or not able to run composer install in the production server then at first try this in local and then deploy the source code to production.
Initially, your application may not throw any exception but there are lots of possibilities there are some features that will not work in PHP 7.3
(by cjy、harshasoysa、Emtiaz Zahid)