
Hey there, Laravel enthusiasts! 👋 I recently had to deploy a Laravel app to shared hosting using cPanel, and boy, was it an adventure. But don’t worry, I’ve got your back! I’m going to share my battle-tested method that’ll work whether you’ve got terminal access or not. Let’s dive in and get that app deployed!
Before we get our hands dirty, let’s chat about why we’re even considering shared hosting. Picture this: you’ve built an awesome Laravel app, but your client is adamant about using their existing shared hosting plan. Frustrating, right? But fear not! With a few tricks up our sleeve, we can make Laravel play nice with cPanel. It’s like teaching a gourmet chef to cook in a small kitchen – challenging, but totally doable!
Alright, let’s start with the scenario where you’re working with one hand tied behind your back – no terminal access. Don’t sweat it, we’ve got this!
First things first, we need to get your Laravel files onto the server. But here’s the twist:
public_html folder!
Why? It’s like hiding your secret recipe – we want to keep the core Laravel files away from prying eyes.Now, let’s get your public assets where they need to be:
public folder and open it.public_html directory.
This step is like setting the table for your guests – we’re putting all the pretty stuff where people can see it.Here’s where it gets a bit tricky, but I believe in you! We need to edit the index.php file:
public_html folder.index.php and right-click it.Code Editor from the menu.Now, depending on your Laravel version, you’ll need to make some changes:
require __DIR__.'/../folderName/vendor/autoload.php';
$app = require_once __DIR__.'/../folderName/bootstrap/app.php';use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../folderName/storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__.'/../folderName/vendor/autoload.php';
// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../folderName/bootstrap/app.php')
->handleRequest(Request::capture());Remember to replace
folderNamewith the actual name of your Laravel root directory. It’s like giving your app a map to find its way home!
Got terminal access? Lucky you! You’ve got a secret weapon that’ll make this process a breeze.
Just like in Method 1, upload your Laravel project to the root directory, not public_html. It’s still our little secret!
Here’s where the magic happens. Open up your terminal and type in this spell:
ln -s /laravel/public/* public_htmlBoom! You’ve just created a magical bridge (symlink) between your Laravel public directory and the public_html folder. It’s like teleporting your files without actually moving them!