cPanel

Deploy a Laravel app on cPanel hosting

Host a Laravel application on cPanel: upload or clone the code, point the domain to the public folder, run Composer, set .env, migrate the database and schedule tasks.

IntermediatecPanel hosting2 min read

Laravel runs well on cPanel hosting with LiteSpeed and a current PHP version. The key point is that only Laravel's public folder should be reachable from the web; everything else, including .env with your secrets, must stay outside the document root. This guide walks through a clean deployment.

Before you start

  • SSH or Terminal access for Composer and Artisan commands.
  • A PHP version supported by your Laravel release, selected in MultiPHP Manager, with extensions such as mbstring, openssl, pdo_mysql, tokenizer, xml, ctype, fileinfo and bcmath enabled.
  • A MySQL database and user: create them.

Put the code outside public_html

  • With Git: clone into ~/apps/myapp using Git Version Control or git clone in Terminal.
  • Without Git: upload a ZIP of the project (without vendor and node_modules) to ~/apps/myapp and extract it in File Manager.

Point the domain to the public folder

  1. Open cPanel → Domains → Domains.
  2. For an addon domain or subdomain, click Manage and set the Document Root to apps/myapp/public, then save.
  3. For the primary domain, whose root is fixed to public_html, either host the app on a subdomain, or replace public_html with a symlink in Terminal after backing it up:
    mv ~/public_html ~/public_html.bak && ln -s ~/apps/myapp/public ~/public_html

Install dependencies and configure

cd ~/apps/myapp
composer install --no-dev --optimize-autoloader
cp .env.example .env && php artisan key:generate

Edit .env in File Manager:

APP_ENV=production
APP_DEBUG=false
APP_URL=https://app.example.com
DB_HOST=localhost
DB_DATABASE=cpuser_app
DB_USERNAME=cpuser_appuser
DB_PASSWORD=your-password

Then run:

php artisan migrate --force
php artisan storage:link
php artisan config:cache && php artisan route:cache && php artisan view:cache

Tip: If php in Terminal is a different version than the website, call the right binary, e.g. /opt/cpanel/ea-php83/root/usr/bin/php artisan migrate.

Build front-end assets

Run npm run build on your computer and upload the public/build folder. Building with Node on shared hosting uses a lot of memory and can hit resource limits.

Scheduler and queues

  • Add a cron job every minute:
    cd /home/cpuser/apps/myapp && php artisan schedule:run >> /dev/null 2>&1
  • Long-running queue:work processes are not suitable for shared hosting. Use QUEUE_CONNECTION=database and process jobs from the scheduler with queue:work --stop-when-empty.

Permissions

storage and bootstrap/cache must be writable by your user; 755 folders and 644 files are enough because PHP runs as your account. Never use 777.

Troubleshooting

  • 500 error, blank page: read storage/logs/laravel.log and the error log. Missing APP_KEY and cached config are common causes; run php artisan config:clear.
  • 404 on every route except /: the document root is not the public folder, or its .htaccess is missing.
  • Composer out of memory: run composer install locally and upload vendor, or contact support.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.