Deployment

How to Deploy a Laravel App to Hosting (cPanel & VPS)

9 min read · By the GudangCode Team

The most nerve-racking moment for a beginner is moving an app from their computer to a public server. The good news is the process is repeatable and predictable. This guide covers the two most common scenarios: cPanel-based shared hosting and a VPS.

Preparation Before Uploading

  • Make sure the host supports the required PHP version (check composer.json).
  • Prepare the production database and note its name, user, and password.
  • Set APP_ENV=production and APP_DEBUG=false for security.

Scenario A: Shared Hosting (cPanel)

1. Upload the files. Compress the project (without vendor/ and node_modules/ to keep it small), upload via File Manager, then extract. If the host provides SSH access, run composer install --no-dev --optimize-autoloader on the server. If not, upload the vendor/ folder from your machine too.

2. Point the document root to public. This is the most frequently missed step. Laravel must only be served through the public folder. There are two ways:

  • Change the domain's document root to .../projectname/public (safest, via the Domains menu in cPanel).
  • Or place the contents of public/ into public_html and adjust the paths in index.php to point to the app folder above it.

3. Configure .env. Create a .env on the server, fill in production database credentials, then run php artisan key:generate and php artisan migrate --force (the --force flag is required in production).

Scenario B: VPS

On a VPS you hold full control. The flow: install PHP, Composer, MySQL, and a web server (Nginx/Apache); pull the code via Git; run composer install --no-dev; configure a virtual host pointing to the public folder; then secure it with an HTTPS certificate (e.g. Let's Encrypt). A VPS offers more performance and flexibility in exchange for greater maintenance responsibility.

Correct Folder Permissions

The biggest source of 500 errors after deployment is write permissions. Ensure the server can write to these two folders:

chmod -R 775 storage bootstrap/cache

Adjust folder ownership to match the web server user if needed.

Production Optimisation

Once the app is visible, speed it up by caching configuration and routes:

php artisan config:cache
php artisan route:cache
php artisan view:cache

Do not forget to run php artisan storage:link if the app displays uploaded files from storage.

Final Checklist

  • The home page opens without error and HTTPS is active.
  • APP_DEBUG=false — error pages do not leak details.
  • Login, registration, and core flows are tested directly in production.
  • Database and file backups are scheduled.

The first deployment is the hardest. Once you master the flow, pushing later updates takes just a few minutes.


Tim Support
Online
Isi data dulu untuk mulai chat:
Beri rating & testimoni sebelum menutup:
Live chat by gudangcode.com