【发布时间】:2018-09-29 05:51:33
【问题描述】:
我已经使用 Homestead 安装了 Laravel,但由于某种原因,我的路由无法正常工作(404 错误),只有默认的“/”可以。
这些是我创建的其他路线:
Route::get('test', function(){ // it doesn't work like so either: "/test"
return "Test";
});
Route::get('user', function(){
return "User";
});
没有一个到达。
如果我列出所有路线,这就是我得到的:
D:\web\laravel>php artisan route:list
+--------+----------+----------+------+---------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | test | | Closure | web |
| | GET|HEAD | user | | Closure | web |
+--------+----------+----------+------+---------+--------------+
知道为什么这些不起作用吗?据我所知,Homestead 中的 web 服务器和 php 不需要任何额外的手动配置来允许这些基本代码工作。
编辑
如果我列出来自 VM 内的路由,我的路由不存在!:
vagrant@homestead:~/code$ php artisan route:list
+--------+----------+----------+------+---------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
+--------+----------+----------+------+---------+--------------+
这是我在 Homestead.yaml 中的共享文件夹配置:
folders:
- map: D:/web/laravel
to: /home/vagrant/code
网站设置:
sites:
- map: homestead.test
to: /home/vagrant/code/public
如果我从 /home/vagrant/code 执行 ls:
vagrant@homestead:~/code$ ls
app bootstrap composer.lock database phpunit.xml readme.md routes storage vendor
artisan composer.json config package.json public resources server.php tests webpack.mix.js
这是我执行“vagrant up --provision”时的输出:
PS C:\Homestead> vagrant up --provision
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Clearing any previously set forwarded ports...
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
homestead-7: Adapter 1: nat
homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
homestead-7: 80 (guest) => 8000 (host) (adapter 1)
homestead-7: 443 (guest) => 44300 (host) (adapter 1)
homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
homestead-7: 4040 (guest) => 4040 (host) (adapter 1)
homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
homestead-7: SSH address: 127.0.0.1:2222
homestead-7: SSH username: vagrant
homestead-7: SSH auth method: private key
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Connection reset. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Connection reset. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Connection reset. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Connection reset. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Remote connection disconnect. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Remote connection disconnect. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Connection reset. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
homestead-7: Warning: Remote connection disconnect. Retrying...
homestead-7: Warning: Connection aborted. Retrying...
==> homestead-7: Machine booted and ready!
==> homestead-7: Checking for guest additions in VM...
homestead-7: The guest additions on this VM do not match the installed version of
homestead-7: VirtualBox! In most cases this is fine, but in rare cases it can
homestead-7: prevent things such as shared folders from working properly. If you see
homestead-7: shared folder errors, please make sure the guest additions within the
homestead-7: virtual machine match the version of VirtualBox you have installed on
homestead-7: your host and reload your VM.
homestead-7:
homestead-7: Guest Additions Version: 5.0.18_Ubuntu r106667
homestead-7: VirtualBox Version: 5.2
==> homestead-7: Setting hostname...
==> homestead-7: Configuring and enabling network interfaces...
==> homestead-7: Mounting shared folders...
homestead-7: /vagrant => C:/Homestead
==> homestead-7: Running provisioner: file...
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
homestead-7: Unable to mount one of your folders. Please check your folders in Homestead.yaml
==> homestead-7: Running provisioner: shell...
homestead-7: Running: C:/Users/[user]/AppData/Local/Temp/vagrant-shell20180424-1628-11jxfyp.sh
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating Certificate: homestead.test
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating Site: homestead.test
==> homestead-7: Running provisioner: shell...
homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Checking for old Schedule
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Clear Variables
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Restarting Cron
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Restarting Nginx
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating MySQL Database: homestead
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating Postgres Database: homestead
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Update Composer
homestead-7: You are running composer as "root", while "/home/vagrant/.composer" is owned by "vagrant"
homestead-7: You are already using composer version 1.6.4 (stable channel).
==> homestead-7: Running provisioner: shell...
homestead-7: Running: C:/Users/[user]/AppData/Local/Temp/vagrant-shell20180424-1628-1j2nixt.sh
==> homestead-7: Running provisioner: shell...
homestead-7: Running: C:/Users/[user]/AppData/Local/Temp/vagrant-shell20180424-1628-ltovu3.sh
我看过这条线:
homestead-7: Unable to mount one of your folders. Please check your folders in Homestead.yaml
它没有提供详细信息。
D:/web/laravel和/home/vagrant/code都有相同的内容,但是我注意到如果我创建一个随机文件,就叫它D :/web/laravel/deleteme.txt,即使我重新加载 vagrant,它也不会显示在 /home/vagrant/code 中。
【问题讨论】:
-
也许他们应该是
/test? -
不。我已经在开始时尝试使用斜线,但也没有用。
-
D:\web\laravel>对我来说似乎不是 linux 路径。 -
你的问题。您编辑了项目的本地版本,但它并未反映您的 VM 中的版本。检查Configuring Shared Folders 部分以获得帮助。
-
我希望我能帮助你,但距离我上次在 Homestead 中使用 Windows 已经有一分钟了,我绝不是这方面的专家。
标签: php laravel routes homestead