Hosting a Laravel 11 project on cPanel shared hosting
Hosting a Laravel 11 project on cPanel shared hosting involves several steps since Laravel is built to work with a virtual host setup (like localhost with public/ as root), but cPanel typically uses public_html/ as the root directory. Here’s a full guide to help you:
✅ Prerequisites
- 
Laravel 11 project ready on your local machine. 
- 
cPanel access (via your hosting provider). 
- 
PHP version on server must be PHP 8.2+. 
- 
Composer installed on server (optional but helpful). 
- 
MySQL database (if needed) created in cPanel. 
📁 Step-by-Step Hosting Guide
1. Structure Your Project for cPanel
By default, Laravel uses public/ as the web root. But cPanel uses public_html/. So you need to move the contents of Laravel's public/ folder into public_html/, and update paths accordingly.
Let’s say your project folder is called laravel11app.
Option A: Simple Adjustment (Recommended for shared hosting)
- 
Compress your entire Laravel project, excluding the vendorfolder (optional to reduce size).
- 
Login to cPanel → File Manager. 
- 
Upload the ZIP to your home directory (e.g., /home/youruser/) — not insidepublic_htmlyet.
- 
Extract the ZIP there — your project files should be in /home/youruser/laravel11app.
Now do the following:
Inside public_html/:
- 
Go into /laravel11app/public/
- 
Copy all contents (including .htaccessandindex.php)
- 
Paste them into public_html/
2. Update index.php Paths
Edit public_html/index.php, update the paths:
require __DIR__.'/../laravel11app/vendor/autoload.php';This tells Laravel to load from your app folder, not from
$app = require_once __DIR__.'/../laravel11app/bootstrap/app.php';
public_html.3. Environment Configuration
In root of your Laravel app (laravel11app/), edit .env:
- 
Set your APP_URL:
APP_URL=https://yourdomain.comSet database details (from your cPanel > MySQL section):
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_cpanel_dbname
DB_USERNAME=your_cpanel_dbuser
DB_PASSWORD=your_cpanel_dbpass
4. Upload vendor Folder and Run Composer
Option A: Upload vendor Folder (if no SSH/composer access)
- 
Run this locally:composer install --optimize-autoloader --no-dev 
- Zip the vendor/folder and upload it to your project root on cPanel.
- Extract it there.
 Option B: If you have SSH access:Login via Terminal/SSH: cd ~/laravel11app 
 composer install --optimize-autoloader --no-dev5. Set Laravel PermissionsFrom cPanel → Terminal or SSH: chmod -R 775 storage 
 chmod -R 775 bootstrap/cacheOr use File Manager to set permissions. 
 🛠️ 6. Run Migrations (if needed)Via SSH or route: php artisan migrate If no SSH, create a temporary route inweb.phpto run migrations once (then delete it):
 Route::get('/migrate', function () { 
 Artisan::call('migrate');
 });
 ✅ Final Notes:- Visit your domain: https://yourdomain.com → It should load your Laravel app.
- Make sure to delete any temporary routes or files used for setup.
- Use .htaccess in public_html/ to enforce HTTPS or custom rules.
 
Would you like a ready-made .htaccess file for Laravel 11 in public_html/
Comments
Post a Comment