Laravel Livewire在XAMPP环境下非php artisan serve运行故障排查求助
XAMPP环境下Laravel Livewire非
php artisan serve模式故障解决方法 配置XAMPP虚拟主机(核心解决步骤)
直接访问public目录会导致Livewire的资源路径、路由解析异常,必须配置虚拟主机:- 打开XAMPP安装目录下的
apache/conf/extra/httpd-vhosts.conf,添加以下配置(替换为你的项目路径):<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/your-laravel-project/public" ServerName your-project.test <Directory "C:/xampp/htdocs/your-laravel-project/public"> AllowOverride All Require all granted </Directory> </VirtualHost> - 编辑系统hosts文件:
- Windows:
C:\Windows\System32\drivers\etc\hosts - Linux/macOS:
/etc/hosts
添加一行:127.0.0.1 your-project.test
- Windows:
- 重启XAMPP的Apache服务,通过
http://your-project.test访问项目,禁止直接访问public目录
- 打开XAMPP安装目录下的
修正项目环境配置
- 打开项目根目录的
.env文件,设置正确的APP_URL:APP_URL=http://your-project.test - 清除配置缓存,避免旧配置生效:
php artisan config:clear
- 打开项目根目录的
验证Livewire资源与路由
- 重新发布Livewire静态资源,确保路径正确:
php artisan livewire:publish --assets - 查看页面源代码,确认Livewire的JS文件路径为
http://your-project.test/livewire/livewire.js,而非相对路径 - 检查路由冲突,执行
php artisan route:list,确保没有自定义路由覆盖Livewire的/livewire/*路由
- 重新发布Livewire静态资源,确保路径正确:
内容的提问来源于stack exchange,提问作者อนันดา สองสกุล
相关产品推荐
相关产品推荐

