How to deploy a Laravel project on cPanel shared hosting
This guide shows you how to deploy a Laravel project on cPanel shared hosting the safe way: keep the code outside the public folder, point the domain to Laravel's public folder, set up .env, run Composer and Artisan, and add the scheduler cron job.
Before you start
- Set the PHP version your Laravel version needs (for example PHP 8.2 or newer for recent releases). See How to change the PHP version.
- Create a MySQL database and user. See How to create a MySQL database and user in cPanel. Note the full names, including the account prefix.
- Terminal access in cPanel makes this much easier. If you do not have it, ask support.
Step 1: Upload the project outside public_html
- Compress your project (without
node_modules, and withoutvendorif you will run Composer on the server). - Upload the ZIP to your home directory with File Manager and extract it into a folder such as
/home/USER/laravel. See How to upload your website.
Never put the whole project inside public_html. That would expose your .env file, which contains passwords.
Step 2: Point the domain to the public folder
Option A, addon domain or subdomain (recommended): in cPanel open Domains, create or manage the domain, and set its document root to laravel/public. Laravel then works exactly as designed.
Option B, main domain: the main domain's document root is public_html. Copy everything inside laravel/public (including .htaccess) into public_html, then edit public_html/index.php and change every __DIR__.'/../ to __DIR__.'/../laravel/. In Laravel 11 and newer the lines look like this:
if (file_exists($maintenance = __DIR__.'/../laravel/storage/framework/maintenance.php')) {
require $maintenance;
}
require __DIR__.'/../laravel/vendor/autoload.php';
(require_once __DIR__.'/../laravel/bootstrap/app.php')
->handleRequest(Request::capture());
With option B, you must copy the public folder again (for example new build assets) after each update.
Step 3: Install dependencies and configure .env
Open Terminal and run:
cd ~/laravel
php -v
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
Check that php -v shows the version you need. If it does not, contact support. If composer is not available, run composer install on your computer and upload the vendor folder too.
Edit .env in File Manager:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=USER_dbname
DB_USERNAME=USER_dbuser
DB_PASSWORD=your-strong-password
Step 4: Migrate, link storage and cache
php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache
migrate --force changes your database, so take a backup first if the database already has data. With option B, storage:link creates the link in laravel/public, so create it in public_html instead:
ln -s /home/USER/laravel/storage/app/public /home/USER/public_html/storage
Your account must be able to write to storage and bootstrap/cache. On our servers 755 for folders and 644 for files is enough. Never use 777.
Step 5: Add the scheduler cron job
In cPanel open Cron Jobs, choose Once Per Minute and add:
cd /home/USER/laravel && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
For queues, use the database queue driver and schedule queue:work --stop-when-empty from your scheduler, because long-running workers are not allowed on shared hosting.
php artisan config:cache again every time you edit .env.Common problems
- 500 error with a blank page: check
laravel/storage/logs/laravel.logand the cPanel error logs. Common causes: missingAPP_KEY, wrong database details or wrong PHP version. - Only the home page works, other routes give 404: the
.htaccessfrompublicis missing in the document root. - Changes in .env are ignored: run
php artisan config:clearthenconfig:cache. - Uploaded images do not show: the storage link is missing or points to the wrong place.
Frequently asked questions
Can I deploy with Git instead of ZIP files?
Yes. Use cPanel Git Version Control (see the Git guide in this category) to pull from GitHub, then run Composer and Artisan.
Can I use Redis or Laravel Horizon?
These need services and long-running processes. Use a VPS for them.
Does Laravel need Node.js on the server?
Only to build front-end assets. Run npm run build on your computer and upload the public/build folder.