将laravel项目部署到Cpanel时如何解决错误404?

时间:2020-10-13 10:27:05

标签: php laravel cpanel

我正在尝试将laravel(Laravel Framework 7.28.3)部署到Cpanel,但是出现404错误。 我将项目上传到/ public_html,修改了index.php文件以指向正确的文件(如下所示)。 我认为index.php文件中肯定有一些错误,但无法弄清楚。 这是我第一次问我的问题(经过几次搜索),希望我能得到答案!

require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

这是我在文件管理器中的文件结构:

file structure in File Manager

2 个答案:

答案 0 :(得分:1)

在Cpanel中部署laravel应用程序

  • 设置1:-将文件上传到 root 目录的 Cpanel 而不是 public_html

  • 设置2:-打开该文件夹,并将公用文件夹的内容移至您的面板的 public_html

  • 设置3:-导航到 public_html 文件夹并找到index.php文件。右键单击它,然后从菜单中选择“代码编辑器”。

并更改此行

require __DIR__.'/../folderName/vendor/autoload.php';
$app = require_once __DIR__.'/../folderName/bootstrap/app.php';

注意:- folderName 此处是您存放应用程序的根目录

就是这样,您所有的请求都将放在 public_html 文件夹index.php中,并且该文件将包含require __DIR__.'/../folderName/vendor/autoload.php;并运行laravel应用程序


文件夹结构看起来像

/laravel
/public_html/index.php

内部index.php

require __DIR__.'/../laravel/vendor/autoload.php';;
$app = require_once __DIR__.'/../laravel/bootstrap/app.php'; // here laravel is folder name

答案 1 :(得分:0)

您需要确保您的应用程序位于public_html之外的文件夹中。

然后,您需要建立一个指向应用程序内公共目录中所有内容的符号链接。此符号链接应放在您的public_html中。

这样,您的业务逻辑将无法从外部获得,而只能从您自己的应用程序获得。

实际上,建议您使用git克隆应用程序,然后按照docs中的步骤进行安装。 (https://laravel.com/docs/7.x/installation