Abd*_*mun 5 deployment cpanel laravel
我想将我的应用程序部署在 Cpanel 上的共享托管上,其中主文档根目录有public_htmlLaravel 项目public
编辑\App\Providers\AppServiceProviderregister() 方法并添加此代码。
// set the public path to this directory
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
Run Code Online (Sandbox Code Playgroud)
打开server.php可以看到这段代码
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
Run Code Online (Sandbox Code Playgroud)
只需将其替换为:
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
require_once __DIR__.'/public_html/index.php';
Run Code Online (Sandbox Code Playgroud)
然后为您的应用程序提供服务php artisan serve,您还可以将其部署在主文档根 public_html 的 Cpanel 共享主机上
您可以将rename公共目录设置为您想要的任何内容,并告诉 Laravel 使用当前目录路径作为公共路径。只需导航到文件夹index.php内部public(或您将其重命名为的任何内容)并在定义后添加以下代码$app:
$app = require_once __DIR__.'/../bootstrap/app.php';
/* *** Add this code: *** */
$app->bind('path.public', function() {
return __DIR__;
});
/* ********************** */
Run Code Online (Sandbox Code Playgroud)
我看到这篇文章解释了如何去做。简而言之,转到public_html/index.php并$app->bind('path.public', function() { return __DIR__; });在创建 $app 之后添加。
要修复 CLI 模式或 Artisan 脚本中使用的脚本的路径,您应该将以下代码添加到文件/bootstrap/app.php
$app->bind('path.public', function() { return base_path().'/public_html'; });
Run Code Online (Sandbox Code Playgroud)
确保在创建 $app 之后添加此行。
更新 在 laravel 10 中,您应该更新代码以调用 Illuminate\Foundation\Application 对象提供的 usePublicPathhave 方法。将此行添加到您的public_html/index.php文件中
app()->usePublicPath(__DIR__);
Run Code Online (Sandbox Code Playgroud)
您可以在此处查看更新的详细信息
| 归档时间: |
|
| 查看次数: |
15959 次 |
| 最近记录: |