How to Deploy Laravel on Shared Hosting the Right Way
Laravel runs well on cPanel shared hosting, but many tutorials take shortcuts that leave the .env file, logs or the whole source tree reachable from the internet. Done properly, a shared hosting deployment is safe, fast with LiteSpeed, and easy to update.
This guide shows the correct structure, the .env settings for production, folder permissions, the scheduler through cron and a practical way to process queues without Supervisor.
The one rule: only the public folder is web-facing
A Laravel project has a public folder that holds index.php, .htaccess and compiled assets. Everything else (app, config, storage, vendor and .env) must stay outside the web root.
The common mistake is to upload the whole project into public_html and add a rewrite rule that sends requests to public/. If that rule ever fails or is overwritten, files such as .env with your database password and APP_KEY become downloadable. Keep the project in its own folder instead:
/home/USER/laravel/ the project (not web-accessible)
/home/USER/laravel/public the only folder the domain should serve
/home/USER/public_html/ the primary domain's default web root
Requirements
- PHP version: Laravel 13 requires PHP 8.3 or newer, and Laravel 12 requires PHP 8.2 or newer. Set it in cPanel under Select PHP Version (CloudLinux) or MultiPHP Manager. Our article on choosing a PHP version explains the differences.
- PHP extensions: Laravel needs ctype, curl, dom, fileinfo, filter, hash, mbstring, openssl, pcre, pdo, session, tokenizer and xml, plus pdo_mysql for MySQL. Most are enabled by default.
- SSH or the cPanel Terminal: strongly recommended, because Artisan and Composer are command-line tools.
- A MySQL database created in cPanel under MySQL Databases.
Step 1: Upload the project outside public_html
- Upload or clone the project into
/home/USER/laravel. Do not uploadnode_modules, and do not upload your local.env. - Install PHP dependencies on the server, without development packages:
Ifcd /home/USER/laravel composer install --no-dev --optimize-autoloadercomposer --versiondoes not work on your server, run the same command locally and upload thevendorfolder. - Build front-end assets on your computer with
npm run buildand upload the resultingpublic/buildfolder. Shared accounts have memory limits that Vite builds often exceed.
Step 2: Point the domain at the public folder
Option A: an addon domain or subdomain
In cPanel, open Domains. When you create the domain, untick the option to share the document root and enter laravel/public as the document root. For an existing addon domain or subdomain, click Manage and change the document root there. This is the cleanest setup.
Option B: the account's primary domain
cPanel does not let users change the primary domain's document root from the Domains page. Your host can change it at the server level, so ask support to point the primary domain to /home/USER/laravel/public.
If that is not possible, copy the contents of laravel/public, including the hidden .htaccess, into public_html and edit public_html/index.php so it loads the framework from the project folder:
<?php
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
if (file_exists($maintenance = __DIR__.'/../laravel/storage/framework/maintenance.php')) {
require $maintenance;
}
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$app->usePublicPath(__DIR__);
$app->handleRequest(Request::capture());
With this method you must copy public/build and any other public assets into public_html after every release, which is why Options A and B are easier to maintain.
Step 3: Configure .env for production
Copy .env.example to .env on the server and set at least these values:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=USER_laravel
DB_USERNAME=USER_laravel
DB_PASSWORD=a-long-random-password
QUEUE_CONNECTION=database
CACHE_STORE=database
SESSION_DRIVER=database
cPanel prefixes database and user names with your account name, so use the full names shown in MySQL Databases. Then generate the application key once:
php artisan key:generate
Never set APP_DEBUG=true on a live site. Debug pages reveal environment values and file paths to anyone who triggers an error.
Step 4: Permissions for storage and bootstrap/cache
On cPanel servers, PHP runs as your own account user, so Laravel can write to folders you own. Standard permissions are enough: 755 for folders and 644 for files.
cd /home/USER/laravel
find storage bootstrap/cache -type d -exec chmod 755 {} \;
find storage bootstrap/cache -type f -exec chmod 644 {} \;
php artisan storage:link
Do not use 777. It is not needed when PHP runs as your user, and security tools on the server may refuse to execute scripts in world-writable folders. If you used the index.php method from Option B, create the storage link by hand instead: ln -s /home/USER/laravel/storage/app/public /home/USER/public_html/storage.
Step 5: Migrate and cache
php artisan migrate --force
php artisan optimize
optimize caches configuration, routes, events and views, which noticeably reduces work on every request. After caching, env() returns null outside the config files, so read settings through config() in your code. Run php artisan optimize:clear if you need to reset the caches.
Step 6: Run the scheduler with a cron job
Laravel's scheduler needs one cron entry that runs every minute. In cPanel, open Cron Jobs, choose "Once Per Minute" and enter:
cd /home/USER/laravel && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
Check which PHP the command line uses with php -v in the Terminal. If it differs from your site's version, use the full path of the right version, for example /opt/alt/php83/usr/bin/php on CloudLinux. Our article on cron jobs explains the timing syntax.
Step 7: Queues without Supervisor
On a VPS you would keep queue:work running with Supervisor. Shared hosting does not allow permanent background processes, but the scheduler can start a short-lived worker every minute. In Laravel 11 and newer, add this to routes/console.php:
use Illuminate\Support\Facades\Schedule;
Schedule::command('queue:work --stop-when-empty --max-time=50')
->everyMinute()
->withoutOverlapping()
->runInBackground();
The worker processes waiting jobs, exits when the queue is empty or after 50 seconds, and the next minute starts it again. Jobs may wait up to a minute, which is fine for emails, notifications and exports. If you need instant processing of large volumes, a VPS is the right tool.
Sending email from Laravel
Password resets and notifications need a working mailer. The simplest option is a mailbox on your own domain, created in cPanel under Email Accounts, used over authenticated SMTP:
MAIL_MAILER=smtp
MAIL_HOST=mail.example.com
MAIL_PORT=465
MAIL_SCHEME=smtps
MAIL_USERNAME=noreply@example.com
MAIL_PASSWORD=the-mailbox-password
MAIL_FROM_ADDRESS=noreply@example.com
Recent Laravel versions use MAIL_SCHEME instead of the older MAIL_ENCRYPTION setting. Shared hosting applies hourly sending limits, so this setup suits transactional mail such as receipts and password resets. Newsletters and large campaigns belong with a dedicated email sending service.
Send a test message after every change to these values, and remember to run php artisan optimize again so the cached configuration picks them up.
Deploying updates
- Run
php artisan downto show a maintenance page. - Pull or upload the new code and run
composer install --no-dev --optimize-autoloader. - Upload the new
public/buildfolder. - Run
php artisan migrate --forceandphp artisan optimize. - Run
php artisan upand test the main pages.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| 500 error with a blank page | Exception with debug off | Read storage/logs/laravel.log |
| Every route except the home page returns 404 | Missing .htaccess in the document root | Copy public/.htaccess again |
| "Vite manifest not found" | Assets were not built or uploaded | Upload public/build |
| "Permission denied" in storage | Files owned by another user or wrong mode | Fix permissions as in Step 4 |
| New .env values ignored | Configuration is cached | Run php artisan optimize again |
For a general approach to these errors, see 500 Internal Server Error: why it happens and reading server logs.
Frequently asked questions
Can I run Horizon, Reverb or Octane on shared hosting?
No. All three need processes that run permanently, which shared hosting does not allow. They work well on a VPS where you control Supervisor or systemd.
Can I deploy Laravel without SSH access?
It is possible by uploading vendor and running migrations through a temporary route, but it is fragile and easy to leave insecure. Use a plan with SSH or Terminal access.
Why do forms show "419 Page Expired"?
The session or CSRF token did not survive the request. Check that APP_URL uses https, that the sessions table exists when SESSION_DRIVER=database, and clear the config cache.
Is LiteSpeed compatible with Laravel's .htaccess?
Yes. LiteSpeed reads Apache-style .htaccess rewrite rules, so the file Laravel ships with works without changes.
Hostinq.com shared hosting runs cPanel with LiteSpeed Enterprise, CloudLinux, selectable PHP versions and unlimited MySQL databases. You can compare plans on the shared hosting page, and our support team can confirm which plan fits a Laravel project that needs SSH access.