Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

php - How to solve Error 404 when deploying laravel project to Cpanel?

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:

file structure in File Manager

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Deploy laravel application in Cpanel

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

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

  • 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.

and change this line

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

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

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


Folder structure will look like

/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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...