DEV3 Technologies home

DEV3 Developer Forum

How do I deploy Laravel 12 on shared hosting with cPanel?

Laravel helpSolved0 views
dev3 ·

My host only gives me cPanel and public_html, no SSH. I uploaded my whole Laravel project into public_html and now the site shows my folder structure and .env is downloadable. What is the correct way to deploy Laravel 12 here?

#laravel#deployment#shared-hosting#cpanel

0

1 reply

dev3 · Accepted answer

Never put the whole project in the web root. Only the contents of public/ must be web-accessible. Your .env being downloadable is a serious leak: rotate APP_KEY, DB passwords and any API keys afterwards.

Recommended layout

/home/user/laravel-app/     <- everything except public/
/home/user/public_html/     <- contents of public/

Steps

  1. Check PHP: Laravel 12 needs PHP 8.2 or newer. Select it in cPanel "MultiPHP Manager" and enable mbstring, openssl, pdo_mysql, fileinfo, ctype, xml, tokenizer.
  2. Run composer install --no-dev --optimize-autoloader locally (or on the server if you have a terminal) and upload the vendor folder, since many shared hosts have no Composer.
  3. Upload the app to laravel-app/, and copy public/* into public_html/.
  4. Edit public_html/index.php to point to the new paths:
require __DIR__.'/../laravel-app/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';

Also change the maintenance file path if present.

  1. Create .env in laravel-app/ with APP_ENV=production, APP_DEBUG=false, a generated APP_KEY (run php artisan key:generate --show locally and paste), and the DB credentials from cPanel.
  2. Import the database (phpMyAdmin) or run migrations if you have SSH: php artisan migrate --force.
  3. Make storage/ and bootstrap/cache/ writable (755 or 775, owned by your user).
  4. Storage link: if you cannot run php artisan storage:link, create the symlink with a one-off route/PHP script, or point FILESYSTEM_DISK public root to a folder inside public_html.

Pitfalls

  • 500 error with a blank page: check storage/logs/laravel.log, then PHP version and missing extensions.
  • Run php artisan config:cache only after .env is final.
  • The scheduler needs a cPanel cron job (see the scheduling topic in this section).

The .env generator can help you draft a production .env.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.