将Laravel核心文件移动到private_html目录

问题描述

为安全起见,我的老板要求我将Laravel 7应用程序移出public_html文件夹,然后移入private_html。

所以我的目录结构如下:

public_html/public/

private_html/ <-- All the rest of the Laravel core files,app,config,routes,.env,etc.

现在,自从我移动文件以来,按预期的那样,访问网站时出现HTTP错误500。

我如何告诉Laravel我的公用文件夹在哪里,以便可以重新开始为我的网页提供服务?我需要编辑哪些配置文件

感谢您的帮助。

编辑1:尝试了Youssef的建议后,一切正常,除了我跑步时

PHP artisan storage:link

我得到:

enter image description here

编辑2:

我能够通过打开config / filesystems.PHP并更改以下内容来修复“ PHP artisan storage:link”:

'links' => [
    public_path('storage') => storage_path('app/public'),],

收件人:

'links' => [
    '/new/directory/public_html/public/storage' => storage_path('app/public'),

然后,当我键入:

PHP artisan storage:link

创建了新的符号链接

解决方法

在public / index.php中,将这两个文件的路径更改为它们的当前路径。

autoload.php的第一行路径

__DIR__.'/../vendor/autoload.php';

require __DIR__.'/../../private_html/vendor/autoload.php';

app.php的第二行路径

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

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

并将其放入\App\Providers\AppServiceProvider register()方法中以设置公共目录的路径。

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

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

如果您需要使用命令直接访问存储的文件,请最终重新分配存储目录的路径:

php artisan storage:link

您还可以将所有文件从public_html/public移至public_html并调整我上面提到的路径