【问题标题】:How to Setup Laravel5.1 App on SharedHost?如何在 SharedHost 上设置 Laravel5.1 应用程序?
【发布时间】:2016-03-15 08:45:57
【问题描述】:

我正在尝试让我的 laravel5.1 应用程序在共享主机上运行,​​但无论我多么努力,我都失败了。 我的主机结构在this image 给出。 laravel 应用程序在 app 文件夹下,laravel 的 public 文件夹的内容被剪切为 public_html。 在 public_html 的 index.php 我有:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../app/bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../app/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

现在我既看不到我的索引页,也看不到 /app/storage/logs/laravel.log 中的任何错误。

顺便说一下,我在 public_html 内容中的 .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]

</IfModule>

【问题讨论】:

    标签: .htaccess laravel-5.1 http-error server-configuration


    【解决方案1】:

    虽然@Adnan 回答可以。重要的是要记住 Laravel 不是为在共享主机上工作而开发的。 上传根目录中的应用程序文件夹也会暴露配置文件。

    这是一个严重的安全问题,应该避免!

    只有“公共”文件夹的内容(或/和资源,如果存在视图)应该在根目录中。所有其他文件必须放在 web 根目录之外。

    我也知道这并不像看起来那么容易。 但如今,您的客户数据的安全性比这更重要!

    那可悲,你当然可以为所欲为!

    希望大家圣诞快乐!

    【讨论】:

    • 感谢您的关注。所以您说将laravel文件夹的内容移动到laravel的嵌套文件夹中?比如 /laravel/app1 ?
    • 我看到你发布的图片表明 Laravel 应用程序文件在 public_html 之外,所以我猜它们也在 web 根目录之外。您的索引文件位于 public_html 文件夹中,这也很好。现在困难的部分是让文件按预期一起工作。这不是那么容易做到的,不能在这里解释。我建议你在谷歌上做一些研究,看看你是否能找到一些东西。我可以为您指出其中的一些:laracasts.com/discuss/channels/general-discussion/….
    【解决方案2】:

    在你的根目录中创建文件夹 laravel 将所有数据复制到该文件夹​​,除了公共文件夹

    然后将所有数据从 public 文件夹复制到文件夹 pubic_html

    现在编辑 public_html 文件夹中的 index.php,如下所示:

    require __DIR__.'/../laravel/bootstrap/autoload.php';
    
    /*
    |--------------------------------------------------------------------------
    | Turn On The Lights
    |--------------------------------------------------------------------------
    |
    | We need to illuminate PHP development, so let us turn on the lights.
    | This bootstraps the framework and gets it ready for use, then it
    | will load up this application so that we can run it and send
    | the responses back to the browser and delight our users.
    |
    */
    
    $app = require_once __DIR__.'/../laravel/bootstrap/app.php';
    

    然后更改Config/database.php并插入数据库连接的有效数据

    Good tutorial

    【讨论】:

    • 感谢您的回答,但没有成功!它仍然在说没有任何日志的内部错误! :|
    • 嗯,我一步一步地做了所有事情,这对我在 godaddy 上有效。我也使用共享主机
    • 只是为了确定,laravel 的存储空间如何permissions?它应该是 775 (rwx rwx r-x)。并在上传之前,确保没有预编译的php,使用php artisan clear-compiled
    猜你喜欢
    • 2011-11-02
    • 2018-12-22
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 2020-11-26
    相关资源
    最近更新 更多