更改 public 文件夹名称后使用 artisan 服务

Using artisan serve after changing the public folder name

与许多主机一样,我们的 public 文件夹名为 public_html。这是在共享主机上,因此无法更改。我已将 public 文件夹更改为 public_html 以反映这一点,但是当我这样做时 artisan serve 停止工作。每次我尝试启动它时,我都会得到:

[ErrorException]
chdir(): No such file or directory (errno 2)

如果我将文件夹重命名回 public,那么 artisan serve 将再次开始工作。

我试过 following this post on laracasts,post 报告中的用户 artisan 为他们工作,但这对我没有影响。如何更改文件夹并让 artisan serve 正常工作?

找到/vendor/laravel/framework/src/Illuminate/Foundation/Application.php这个文件
并更改以下功能

/**
 * Get the path to the public / web directory.
 *
 * @return string
 */
public function publicPath()
{
    return $this->basePath.DIRECTORY_SEPARATOR.'public_html';
}

Dipesh 的回答实际上是一个非常糟糕的主意 - 只要您使用 Composer install/update/require,这些更改就会被吹走。 切勿直接编辑 vendor 目录中的任何内容。

相反,在 bootstrap/app.php 中,您应该添加:

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

紧接着

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__ . '/../')
);

请参阅 https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 以了解进一步的讨论以及安全执行此操作的替代方法。

你也可以extend Illuminate\Foundation\Application。这对于 Laravel CLI(任何以 php artisan 开头的东西)来说似乎是必要的。