Laravel Valet+全站点报apcu_fetch()未定义错误 求修复方案
Fixing Valet+ After Interrupted
valet use 7.1 Operation Hey there, let's work through this issue—interrupting the PHP version switch left Valet+ in a broken state where the APCu extension isn't properly set up for PHP 7.1. Here's a step-by-step fix:
1. Verify & Install APCu Extension for PHP 7.1
The apcu_fetch() error means PHP 7.1 doesn't have the APCu extension enabled or installed correctly. Let's fix that first:
- Check if APCu is already installed for PHP 7.1:
If you get no output, proceed to install it.php7.1 -m | grep apcu - Install the compatible APCu version (PHP 7.1 requires APCu ≤ 5.1.x):
(If you get a "pecl not found" error, runpecl install apcu-5.1.21brew install php@7.1first to ensure the full PHP 7.1 setup is present.) - Enable APCu in PHP 7.1's config:
- Find PHP 7.1's ini file location:
php7.1 --ini - Open the
php.inifile (look for the "Loaded Configuration File" path) and add these lines at the end:extension="apcu.so" apc.enable_cli=1
- Find PHP 7.1's ini file location:
2. Force Re-Switch PHP Version & Restart Valet+
The interrupted valet use 7.1 likely left Valet+ pointing to a misconfigured PHP instance. Let's reset this:
- Stop all Valet+ services first:
valet stop - Force switch to PHP 7.1 to ensure all configurations are overwritten:
valet use 7.1 --force - Restart Valet+ to apply changes:
valet restart
3. Perform a Clean Valet+ Reinstallation (If Steps 1-2 Fail)
If the above doesn't fix it, we'll wipe Valet+ completely and start fresh:
- Uninstall Valet+ with force to remove all traces:
valet uninstall --force - Delete Valet's local configuration directory:
rm -rf ~/.valet - Remove the Valet+ package from your global Composer setup:
rm -rf ~/.composer/vendor/weprovide/valet-plus - Reinstall Valet+ globally:
composer global require weprovide/valet-plus - Run the Valet+ installation setup again:
valet install - Switch back to PHP 7.1:
valet use 7.1 --force
4. Verify the Fix
After completing the steps above:
- Check if APCu is working for PHP 7.1:
You should seephp7.1 -r "var_dump(function_exists('apcu_fetch'));"bool(true)if it's enabled correctly. - Test your Valet+ sites by visiting them in the browser—they should no longer throw the
apcu_fetch()fatal error.
内容的提问来源于stack exchange,提问作者nklatt
相关产品推荐
相关产品推荐

