将laravel项目部署到Cpanel时如何解决错误404? [英] How to solve Error 404 when deploying laravel project to Cpanel?

查看:79
本文介绍了将laravel项目部署到Cpanel时如何解决错误404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to deploy my laravel (Laravel Framework 7.28.3) to Cpanel, but got a 404 error. I uploaded my project into /public_html, modified the index.php file to point to the correct files (as below). I think there must be some mistake in the index.php file but couldn't figure it out. This is my first time asking my question (after searching for it several times), so hope that I will get the answer!

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

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

this is my file structure in File Manager:

推荐答案

在Cpanel中部署laravel应用程序

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

    Deploy laravel application in Cpanel

    • Setup 1 : - upload file to Cpanel the root directory – not the public_html.

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

      Setup 2 : - Open the that folder and MOVE the CONTENTS of the public folder to your cpanel’s public_html .

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

      Setup 3 : - Navigate to the public_html folder and locate the index.php file. Right click on it and select Code Editor from the menu.

      并更改此行

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

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

      NOTE : - folderName here is in root where you laravel application stay

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

      that's it now all your request will come inside public_html folder index.php and this file will include require __DIR__.'/../folderName/vendor/autoload.php; and run laravel application

      /laravel
      /public_html/index.php
      

      indside index.php

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

      这篇关于将laravel项目部署到Cpanel时如何解决错误404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆