agyanadda@gmail.com

Laravel Deployment

Advanced Laravel 1 min read Updated Dec 2, 2026 Topic 30 of 31

Moving Laravel from your computer to a live server needs a few extra steps.

Server requirements

PHP with required extensions (mbstring, openssl, pdo_mysql, xml, ctype, json, bcmath, fileinfo), Composer, a database and SSH access (recommended).

Production .env

  • APP_ENV=production, APP_DEBUG=false, correct APP_URL with https://
  • A unique APP_KEY (run php artisan key:generate only once; changing it breaks encrypted data and logs users out)
  • Live database and mail settings

Deployment commands

Run the commands in the example in order: get the code, install dependencies without dev packages, migrate with --force, link storage and cache everything.

Web server

Point the domain's document root to the public folder. Make storage and bootstrap/cache writable by the web server.

After every update

Pull the code, run composer install, migrate --force, npm run build if assets changed, then php artisan optimize and queue:restart.

Before you go live

Back up the database before running migrations, and test on a staging copy first if you can.

Example

Example — Typical deployment on a VPS Bash
cd /var/www/myapp

# 1. Get the latest code
git pull origin main

# 2. PHP packages without dev tools
composer install --no-dev --optimize-autoloader

# 3. Database changes (--force is required in production)
php artisan migrate --force

# 4. Front-end assets (if you use Vite)
npm ci && npm run build

# 5. Public storage link (first deploy only)
php artisan storage:link

# 6. Cache config, routes, views and events
php artisan optimize

# 7. Reload queue workers
php artisan queue:restart

# Permissions (first deploy)
sudo chown -R www-data:www-data storage bootstrap/cache

After these steps, the site runs the new code with cached config and routes. If something looks wrong, check storage/logs/laravel.log.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Where should the domain's document root point?

Exercise 2 True / False

You should run php artisan key:generate on every deployment.

Exercise 3 Fill in the Blank

In production, php artisan migrate needs the --___ option.

Frequently Asked Questions

Upload the project outside public_html, put the contents of the public folder in public_html, and update the paths in index.php. Set up .env and import the database through phpMyAdmin. If your host offers SSH or Git deployment, use it; it is much safer and easier.