dryk50495 2013-11-14 19:01
浏览 40

Laravel 4路由过去索引页面不适用于webfaction

I am trying to use WebFactions to host my website built with Laravel 4. I have been successful in following tutorials like this: http://euantor.com/using-laravel-with-webfaction/

The index page loads perfectly, but there seems to be a problem with any other page that I link to, giving a 500 error (suggesting that routes.php isn't working somehow).

Looking into things, it seems that I need to change the httpd.conf for the apache server, which I do not have access to on webfactions. I have tried using both .htaccess files offered by laravel (the default one it ships with, as well as this one):

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

But this also didn't seem to solve the problem. Does anyone know of a way to get Laravel 4 working on webfactions so that further routes past the index page works?

  • 写回答

1条回答 默认 最新

  • douliao5550 2013-11-14 23:31
    关注

    First of all, you do not need to change httpd.conf of your virtual host to make Laravel function properly.

    Based on the limited amount of information that you have provided, it is impossible to tell what is wrong with your configuration. However, I can provide you with a working example configuration from my web sites at Webfaction (not Webfactions).

    Directory structure

    /home/myuser
    |--> webapps
    |  --> mysite  (This is your public web directory)
    |--> laravelapps
       --> mysite  (Laravel installation, incl. routes.php)
         --> app
           --> models
           --> views
           --> etc.
    

    For the sake of security, you should have separate folders for web content and Laravel files. In other words, do not place Laravel files and configurations under your public web directory.

    Web directory

    Put any file that needs to be fetched via HTTP protocol into this directory: webapps/mysite. For example, create sub-directories css, js, images and so on.

    Also make sure that you have two Laravel files in the root of your web directory:

    • .htaccess
    • index.php

    .htaccess.php at your web directory

    <IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    </IfModule>
    

    What this does is to redirect all your Laravel requests to index.php. For a more detailed description of the lines, check this answer regarding a very similar .htaccess: This is the .htaccess code in WordPress. Can someone explain how it works?

    index.php at your web directory

    There are two important entries in this file. First one is within section Register The Auto Loader. Make sure that you have something like this (can be also a relative path):

    require '/home/myuser/laravelapps/mysite/bootstrap/autoload.php';

    The second important entry is within the section Turn On The Lights. Make sure it says something like this (again can be a relative path as long as you get it right):

    $app = require_once '/home/myuser/laravelapps/mysite/bootstrap/start.php';

    Laravelapps' Public Path

    One more thing to change is located at /home/myuser/laravelapps/mysite/bootstrap/paths.php within the section Public Path. Make sure it points back to yout web folder, such as:

    'public' => '/home/myuser/webapps/mysite',

    Other stuff

    The settings above should do the trick. However, based on the (lack of) information you provided, it is impossible to rule out other issues with additional Laravel configuration files (located at /home/myuser/laravelapps/mysite/app/config or file permissions). Please, try the things above first and let us know how it goes?

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?