Starting as a Laravel developer was fun and interesting, until it came to deploying it on a Shared Hosting. There was always the issue of placing /public
on the link, and that was not professional at all. It denied the entire site the authenticity it needed. This shot will save you the hassle and hold your hand throughout the process. We will break down the process into steps for better understanding.
In this shot, we are making the following assumptions:
You know how to upload a Laravel application to cPanel from your local server.
You know how to set up your .env
file while on the shared hosting.
The only thing you will learn is ensuring that your application is accessed, e.g., yoursite.com
and not yoursite.com/public
.
You only have to follow two steps to deploy a Laravel application to cPanel without /public
.
Cut the index.php
and .htaccess
files from the public folder and paste them into the project root.
Open and paste the code below in line 24 in index.php
, and save.
require__DIR__.'/vendor/autoload.php';
In line 38, add the line below:
$app = require_once__DIR__.'/bootstrap/app.php';
Deploying a Laravel application to a shared hosting won’t require running the php artisan serve
command.