gpt4 book ai didi

php - 如何在 laravel 5 中将公用文件夹更改为 public_html

转载 作者:IT王子 更新时间:2023-10-29 00:59:58 24 4
gpt4 key购买 nike

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

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

最佳答案

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

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

在您的 index.php 中添加以下 3 行。

/*
|--------------------------------------------------------------------------
| 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() 方法中。

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

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

关于php - 如何在 laravel 5 中将公用文件夹更改为 public_html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30198669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com