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

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

推荐答案

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

请参阅: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提到的,另一个 Select (更可取)是将其放入\App\Providers\AppServiceProviderregister()方法中.

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

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

Php相关问答推荐

使用PHP 7.4在ZipArchive中设置目录mtime

从产品中获取WooCommerce产品属性单选按钮的列表WP_Query

在WooCommerce产品变体SKU字段旁边添加自定义输入字段

将文件添加到存档,而不重建存档

WHERE方法不能与有效查询Laravel一起使用

有没有可能从composer 过时的输出中隐藏不需要的主要版本?

删除了数组中的值,而不是多个数组

创建一个Woocommerce我的帐户订单页面,仅显示已完成的订单

如何在WordPress REST API中判断应用程序密码

Laravel路由到控制器传输变量解决方案需要

根据WooCommerce中的自定义用户元数据值更改用户角色

如果WooCommerce购物车在 checkout 时被清空,请重定向至store 页面

Laravel处理belongToMany和额外字段

表单提交返回空白页

Shopware 6插件:由于删除了配置密钥,更新后配置值不正确

我不明白为什么我收到未定义的数组键异常错误 - Laravel 9 PHP 8

主机中未检索用户表数据

PHP 中的正则表达式,具有字符范围,但不包括特定字符

使用 --exclude-dir 选项从 PHP 执行 grep 时出现问题

路由未定义的 laravel 导出