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

Laravel+Livewire部署XAMPP报错:未指定应用加密密钥

解决Laravel Livewire部署到XAMPP后的加密密钥错误

以下是针对该问题的排查和解决步骤:

  • 确认.env文件存在且配置有效
    确保XAMPP服务器上的项目根目录下存在.env文件,且其中APP_KEY字段已被正确填充(格式类似APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)。如果服务器上没有.env,可直接从本地复制,或在服务器端重新执行php artisan key:generate生成密钥。

  • 修复目录权限
    给Laravel项目的storage和bootstrap/cache目录设置正确的读写权限,让XAMPP的运行用户(通常是apache或www-data)能访问这些文件夹:

    • Linux/macOS环境执行:
      chmod -R 755 storage bootstrap/cache
      chown -R www-data:www-data storage bootstrap/cache
      
    • Windows环境右键文件夹,在「属性-安全」中给IIS_IUSRS或当前用户添加读写权限。
  • 重新生成配置缓存
    先彻底清除现有缓存,再重新生成配置缓存:

    php artisan optimize:clear
    php artisan config:cache
    

    注意:执行config:cache前必须确保.env中的APP_KEY已正确设置,否则缓存会固化无密钥的配置。

  • 启用Apache的mod_rewrite模块
    打开XAMPP的httpd.conf配置文件,确保mod_rewrite模块已启用(去掉行首的#):

    LoadModule rewrite_module modules/mod_rewrite.so
    

    同时确认项目public目录下的.htaccess文件包含正确的Laravel重写规则,默认内容如下:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]
    
        # Send Requests To Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    
  • 验证PHP版本一致性
    检查XAMPP的PHP版本是否与本地开发环境一致,版本差异可能导致配置加载或Livewire运行异常。

内容的提问来源于stack exchange,提问作者Daniel Xavier

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 17:48:10