我已经在家园中安装了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,即使我重新加载流浪汉,它也不会显示在/ home / vagrant / code中。
答案 0 :(得分:1)
您是否检查过您启用了mod_rewrite?
另外,请检查您的公共目录
<Directory "/path/to/your/directory">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
答案 1 :(得分:0)
我认为您需要对配置执行此操作:
从:
folders:
- map: D:/web/laravel
to: /home/vagrant/code
为:
folders:
- map: D:/web/laravel/code
to: /home/vagrant/code
答案 2 :(得分:0)
你在窗户上,对吧?
更改
folders:
- map: D:/web/laravel
to: /home/vagrant/code
到
folders:
- map: D:\web\laravel
to: /home/vagrant/code
如果您只有一个项目,请改为运行而不是--provision
。
答案 3 :(得分:0)
这个怎么样?
folders:
- map: ~/code
to: /home/vagrant/code
站点: - map:homestead.test to:/ home / vagrant / code / public
或者有时这个问题是.htaccess问题尝试检查 mod_rewrite
<Directory "/path/to/your/directory">
Options Indexes FollowSymLinks
AllowOverride 'none' /** or something change to all */
Require all granted
</Directory>
AllowOverride All
希望能给你一个想法。
答案 4 :(得分:0)
我还检查.htaccess文件是否存在,您可以找到laravel online的默认htaccess文件。如果存在.htaccess文件,那么我会做一个PHP工匠路线:clear和PHP artisan config:clear,有时候配置和路线会播放。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>