本文介绍了如何在 Laravel 5 中将公共文件夹更改为 public_html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是共享主机,它使用 cPanel 作为其控制面板,并且在 cPanel 中 public_html 是默认根目录,因此我无法让我的 Laravel 应用程序正常工作.

I'm using a shared hosting which uses cPanel as its control panel and within the cPanel public_html is the default root directory, because of this I can't get my Laravel application work properly.

有没有办法让 Laravel 使用 public_html 而不是 public 文件夹?

Is there any way to make Laravel use public_html instead of public folder?

推荐答案

通过简单的搜索很容易找到.

Quite easy to find this with a simple search.

参见:https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5

在 index.php 中添加以下 3 行.

In your index.php add the following 3 lines.

/*
|--------------------------------------------------------------------------
| 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__.'/../bootstrap/app.php';

// set the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

正如 Burak Erdem 提到的,另一种选择(更可取)是将它放在 \App\Providers\AppServiceProvider register() 方法中.

As Burak Erdem mentioned, another option (and more preferable) is to put this in the \App\Providers\AppServiceProvider register() method.

/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    // ...

    $this->app->bind('path.public', function() {
        return base_path('public_html');
    });
}

这篇关于如何在 Laravel 5 中将公共文件夹更改为 public_html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 10:01