You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:
    php7.1 -m | grep apcu
    
    If you get no output, proceed to install it.
  • Install the compatible APCu version (PHP 7.1 requires APCu ≤ 5.1.x):
    pecl install apcu-5.1.21
    
    (If you get a "pecl not found" error, run brew install php@7.1 first to ensure the full PHP 7.1 setup is present.)
  • Enable APCu in PHP 7.1's config:
    1. Find PHP 7.1's ini file location:
      php7.1 --ini
      
    2. Open the php.ini file (look for the "Loaded Configuration File" path) and add these lines at the end:
      extension="apcu.so"
      apc.enable_cli=1
      
    This ensures APCu works in CLI mode, which Valet+ uses for its server script.

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:
    php7.1 -r "var_dump(function_exists('apcu_fetch'));"
    
    You should see 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:13:30