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

Laravel存储目录别名配置报错:访问URL触发致命错误求助

解决方法

1. 修正HTTPS虚拟主机配置

你访问的是https://testv.localhost,但当前仅配置了HTTP(80端口)的虚拟主机,HTTPS请求会走默认配置,导致Alias规则不生效。在httpd-vhost.conf中添加443端口的虚拟主机配置,并将Alias规则移入其中:

<VirtualHost *:443>
    ServerAdmin admin@testv.localhost
    DocumentRoot "C:/xampp81/htdocs/testv/public"
    ServerName testv.localhost
    ServerAlias www.testv.localhost
    ErrorLog "logs/testv.localhost-error.log"
    CustomLog "logs/testv.localhost-access.log" common
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    
    Alias /storage/pub "C:/xampp81/htdocs/testv/storage/app/public/uploads"
    <Directory "C:/xampp81/htdocs/testv/storage/app/public/uploads">
        Options Indexes FollowSymlinks MultiViews Includes
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

同时修正原HTTP虚拟主机的ServerAdmin字段(去掉多余的点):

ServerAdmin admin@testv.localhost

2. 让Apache优先处理Alias请求

Laravel根目录下public/.htaccess的重写规则会将所有请求转发到index.php,导致Alias规则被覆盖。在public/.htaccess的RewriteEngine On之后添加以下规则,让/storage/pub路径的请求直接由Apache处理,跳过Laravel路由:

RewriteRule ^storage/pub/ - [L]

完整的.htaccess示例片段:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    # 新增规则,跳过Laravel路由处理
    RewriteRule ^storage/pub/ - [L]

    # 原有的Laravel重写规则
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

3. 验证Apache模块状态

确保Apache已开启mod_alias和mod_rewrite模块:

  • 打开XAMPP控制面板,点击Apache的Config按钮,选择httpd.conf
  • 确认以下两行没有被注释(去掉前面的#):
    LoadModule alias_module modules/mod_alias.so
    LoadModule rewrite_module modules/mod_rewrite.so
    

4. 检查目录权限

确保C:/xampp81/htdocs/testv/storage/app/public/uploads目录的权限允许Apache进程访问:

  • 右键该目录,选择「属性」→「安全」
  • 添加Apache运行用户(通常是NT AUTHORITY\SYSTEM或Apache),并赋予读取和执行权限

5. 重启Apache

完成以上配置后,重启XAMPP中的Apache服务,使配置生效。


错误原因说明

你遇到的PHP致命错误是因为/storage/pub的请求被Laravel的前端控制器index.php接管,但Laravel没有对应路由,错误处理过程中因请求上下文未正确初始化,导致调用send()方法时对象为null。通过调整Apache配置让Alias规则优先生效,即可避免请求进入Laravel的处理流程。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 06:15:15