在Ubuntu 14.04和PHP 5.5上无法获得任何路由在Laravel 4.2中工作


Unable to get any routes to work in Laravel 4.2 on Ubuntu 14.04 with PHP 5.5

我正在努力让Laravel 4.2在我的数字海洋服务器上运行Ubuntu 14.04和PHP 5.5。我可以得到显示Laravel标志的屏幕,上面写着"您已经到达"。我很累,而且很晚了,但是我很沮丧,我今晚真的必须把这个工作完成。

我的路由如下:

<?php
Route::get('/', function()
{
    return View::make('hello');
});
Route::any('monkey', function()
{
    return View::make('monkey');
});
Route::resource('search', 'SearchController');
?>

我不能让它说"你好"或"猴子"。给什么?

我已经进入Apache .conf,将AllowOverride从none更改为All,并重新启动Apache服务。

我的laravel.log文件显示:production.ERROR: exception 'Symfony'Component'HttpKernel'Exception'MethodNotAllowedHttpException'

更新:我只是试着添加以下路由没有改变…

<?php
Route::any('test', function()
{
    return 'Test This!!!';
});
?>
更新2:

这是我的。htaccess文件在public:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

您需要启用mod_rewrite,因为默认情况下它通常不启用

在终端中执行如下命令启用。

a2enmod rewrite

然后重启Apache:

service apache2 restart

您必须在app/public/目录下创建.htaccess文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>