将Laravel从5.4升级到5.5.0时遇PHP版本不符问题求助
Hey there, let's work through this frustrating PHP version mismatch you're hitting. It's super common with WAMP since the web server's PHP version doesn't always match what your command line (CLI) is using. Here's how to resolve it step by step:
1. Confirm the CLI PHP Version
First, let's check what PHP version your command line is actually using—this is what Composer relies on. Open a command prompt and run:
php -v
If this outputs 5.6.31 instead of 7.1.9, that's the root of your problem. WAMP lets you switch PHP versions for the web, but the CLI might still be pointing to an older version.
2. Update System Environment Variables to Use the Correct PHP Version
To fix the CLI version, we need to prioritize WAMP's 7.1.9 PHP in your system's Path:
- Locate your WAMP PHP 7.1.9 directory (usually something like
C:\wamp64\bin\php\php7.1.9) - Open System Properties → Advanced → Environment Variables
- Under System Variables, find the
Pathvariable and edit it - Move the path to
php7.1.9to the top of the list (so it gets picked before any older PHP versions) - Click "OK" to save changes, then close and reopen your command prompt (this is crucial—old sessions won't pick up the new Path)
3. Verify the Fix
Run php -v again in the fresh command prompt. It should now show 7.1.9. You can also double-check with Composer:
composer diagnose
Look for the "PHP version" line in the output—it should match 7.1.9.
4. Retry the Laravel Upgrade
Now you can run your upgrade command again, like:
composer update laravel/framework:5.5.*
Composer should now detect the correct PHP version and proceed without the version mismatch errors.
Why This Happens
WAMP often leaves older PHP versions in your system Path by default. When you switch PHP versions in the WAMP manager, it only updates the web server configuration—not the command line's default PHP executable. That's why you saw 7.1.9 in WAMP but 5.6.31 during the upgrade.
内容的提问来源于stack exchange,提问作者Salim Maulaie

