我是 Laravel 新手。
我已经通过 Oracle VirtualBox 设置了 Fedora 23 服务器,安装了 Composer 并创建了一个 Laravel 5.3 项目作为 html 文件夹(为了方便起见,因为只需虚拟机的 IP 地址即可访问它)。我还禁用了它的防火墙,因为这只是为了测试/学习。
我向存储文件夹授予了 755 权限,只需输入 http://«IP» 即可在浏览器上显示欢迎页面。
我创建了一个index.blade.php View ,其代码与welcome.blade.php相同,但将Laravel一词更改为“Something”。现在问题来了。
我创建了一个 HomeController.php Controller ,这样我就可以毫无错误地获取 php artisan 路由:缓存,因为如果我返回 paths/web.php 文件上的 View ,它会给我一个错误:
[myuser@webserver]$ php artisan route:cache
Route cache cleared!
[LogicException]
Unable to prepare route [/] for serialization. Uses Closure.
所以我的文件看起来像这样:
路线/web.php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
/*
Route::get('/', function () {
return view('welcome');
});
Route::get('home', function () {
return view('index');
});
*/
Route::get('/', 'HomeController@getWelcomePage');
Route::get('home', 'HomeController@homepage');
应用程序/Http/Controllers/HomeController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class HomeController extends Controller
{
public function homepage(){
return view('index');
}
public function getWelcomePage(){
return view('welcome');
}
}
公共(public)/.htaccess
<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>
/etc/httpd/conf/httpd.conf(为了长度目的,我删除了示例中的注释行)
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html/public"
<Directory "/var/www">
AllowOverride none
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
完成这一切后,我可以通过输入http://«IP»看到欢迎页面,但如果我输入http://«IP»/home,我只会看到一个空白页面。浏览器告诉我,该页面返回了 500 内部服务器错误,但是在 storage/logs/laravel.log 中没有显示任何内容(最后一个日志是由于 php artisan Route:cache 由于 View 而无法执行而导致的错误)在 web.php 文件中返回)
[2017-01-19 13:00:49] local.ERROR: exception 'LogicException' with message 'Unable to prepare
route [/] for serialization. Uses Closure.'
in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:995
对我来说最奇怪的部分是,如果我评论路由文件中的所有条目,我会得到 http://«IP»/home 的路由未找到异常,但如果我只输入 http://«IP » 我仍然得到欢迎 Blade 。
我相信我的问题非常简单,但经过几个小时的搜索和尝试/错误,我仍然无法解决这个问题。
欢迎任何帮助/建议。
编辑:我的问题不是关闭错误,我为路由创建了 Controller 方法。我的问题是服务器只提供欢迎 Blade ,所有其他服务器都给我一个 500 内部服务器错误
最佳答案
终于明白了!
阅读 https://woohuiren.me/blog/installing-laravel-5-on-fedora/ 的评论后,一位显然与我有同样问题的用户说了以下内容:
Seem issue this command solve the blank page (error code 500)
$ cd laravel_project
$ php artisan cache:clear
$ chmod -R 777 storage
$ composer dump-autoload
I set SElinux to permissive, should be ok right?
我的页面显示没有任何问题。
关于php - Laravel 路线似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41747969/