Laravel is the most popular PHP framework for a reason — elegant syntax, powerful tools like Eloquent ORM and Artisan CLI, built-in support for queues, caching, and authentication. But deploying a Laravel application to production requires more than just uploading files to a server.
This step-by-step guide walks you through deploying Laravel on DeployBase, from initial setup to database configuration, queue workers, caching with Redis, and production optimization. Every step uses only the terminal and confirmed DeployBase features — no guesswork.
Why DeployBase for Laravel Hosting?
Most shared hosting providers support PHP but treat Laravel hosting as an afterthought. You end up fighting with file permissions, missing PHP extensions, and no SSH access to run Artisan commands. DeployBase is different:
- One-click Laravel setup — Select Laravel as your application type and DeployBase provisions your environment with the right PHP version and extensions.
- SSH access on all plans — Run Artisan commands, Composer, and manage your application from the terminal. No plan upgrades required.
- MySQL and PostgreSQL databases — Choose the database that fits your application. Laravel works beautifully with both.
- Redis support — Laravel uses Redis for caching, sessions, and queues out of the box. DeployBase makes Redis available from the dashboard.
- Free SSL certificates — Every Laravel app gets HTTPS automatically on all plans.
- Custom domain support — Connect your own domain to your production Laravel application.
- Built-in file manager — Upload files through the browser when SSH is not convenient.
Step 1: Prepare Your Laravel Application
Before deploying, make sure your Laravel project is production-ready.
Check Your Laravel Version
# Check your Laravel version locally
php artisan --version
# Make sure composer.lock is committed
git status | grep composer.lock
Environment Configuration
Laravel uses a .env file for configuration. Your local .env should never be deployed to production — you will create a production-specific one on the server. Make sure .env is in your .gitignore:
# .gitignore (should already include these)
/vendor
/node_modules
.env
.env.backup
storage/*.key
Optimize for Production Locally
Test that your application runs correctly in production mode before deploying:
# Test production config locally
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Run all tests
php artisan test
# Clear caches after testing
php artisan optimize:clear
Step 2: Create Your Laravel App on DeployBase
Log in to your DeployBase dashboard and create a new hosting instance. Select Laravel as your application type.
DeployBase will provision your environment with PHP and the extensions Laravel requires. Once setup completes, you will have SSH credentials and a default URL.
Step 3: Deploy Your Code
SSH into your DeployBase server and deploy your Laravel application.
Connect via SSH
ssh your-user@your-app.deploybase.io
Clone from GitHub
The recommended approach — clone your repository directly on the server:
# Clone your Laravel project
git clone https://github.com/youruser/your-laravel-app.git
cd your-laravel-app
# Install PHP dependencies (no dev packages in production)
composer install --no-dev --optimize-autoloader
Alternative: Upload via SCP
# From your local machine (exclude vendor and node_modules)
rsync -avz --exclude='vendor' --exclude='node_modules' --exclude='.env' \
./your-laravel-app/ your-user@your-app.deploybase.io:~/your-laravel-app/
# Then SSH in and install dependencies
ssh your-user@your-app.deploybase.io
cd your-laravel-app
composer install --no-dev --optimize-autoloader
Step 4: Configure Your Environment
Create your production .env file on the server:
cd your-laravel-app
cp .env.example .env
nano .env
Set your production configuration:
APP_NAME="Your App Name"
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL=https://yourdomain.com
LOG_CHANNEL=stack
LOG_LEVEL=error
# Database (MySQL example)
DB_CONNECTION=mysql
DB_HOST=your-db-host
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_user
DB_PASSWORD=your_password
# Or PostgreSQL
# DB_CONNECTION=pgsql
# DB_HOST=your-db-host
# DB_PORT=5432
# DB_DATABASE=your_database
# DB_USERNAME=your_user
# DB_PASSWORD=your_password
# Redis (for cache, sessions, queues)
REDIS_HOST=your-redis-host
REDIS_PORT=6379
REDIS_PASSWORD=null
# Cache and session drivers
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis
# Mail (configure your mail provider)
MAIL_MAILER=smtp
MAIL_HOST=smtp.your-provider.com
MAIL_PORT=587
MAIL_USERNAME=your-email
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="${APP_NAME}"
Generate the Application Key
# Generate a secure APP_KEY
php artisan key:generate
# Verify it was added to .env
grep APP_KEY .env
Important: Never set APP_DEBUG=true in production. Debug mode exposes sensitive configuration details, database credentials, and stack traces to anyone who triggers an error.
Step 5: Set Up Your Database
Provision a database from your DeployBase dashboard. Laravel supports both MySQL and PostgreSQL — choose whichever fits your application.
MySQL Setup
# Test the connection
mysql -h your-db-host -u your_user -p your_database -e "SELECT 1;"
# Run migrations
php artisan migrate --force
# Seed the database (if you have production seeders)
php artisan db:seed --class=ProductionSeeder --force
PostgreSQL Setup
If you prefer PostgreSQL (recommended for applications using JSON columns, full-text search, or complex queries):
# Update .env
DB_CONNECTION=pgsql
DB_PORT=5432
# Test the connection
psql -h your-db-host -U your_user -d your_database -c "SELECT 1;"
# Run migrations
php artisan migrate --force
Make sure the pdo_pgsql PHP extension is available. DeployBase's Laravel environment includes the common PHP extensions, but verify with:
php -m | grep pgsql
Step 6: Set Up Redis
Laravel integrates with Redis for three critical features: caching, session storage, and job queues. Provision Redis from your DeployBase dashboard, then configure it.
Install the PHP Redis Extension
# Check if phpredis is available
php -m | grep redis
# Laravel also supports predis as a pure PHP alternative
composer require predis/predis
Configure Redis in .env
REDIS_HOST=your-redis-host
REDIS_PORT=6379
REDIS_PASSWORD=null
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis
Test the Connection
# Test Redis via Artisan tinker
php artisan tinker
>>> Illuminate\Support\Facades\Redis::ping();
# Should return "PONG"
>>> exit
Redis for Caching
With CACHE_DRIVER=redis, Laravel automatically caches configuration, routes, views, and application data in Redis:
# Cache your config and routes for production performance
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Verify cache is working
php artisan tinker
>>> cache()->put('test', 'working', 60);
>>> cache()->get('test');
# Should return "working"
>>> exit
Redis for Queues
Laravel queues let you defer time-consuming tasks (sending emails, processing images, generating reports) to background workers:
# Start a queue worker
php artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
# For production, use a process manager to keep the worker running
pm2 start "php artisan queue:work redis --sleep=3 --tries=3 --max-time=3600" \
--name "laravel-queue" --interpreter=none
Step 7: File Permissions and Storage
Laravel needs write access to specific directories. Set the correct permissions:
# Set directory permissions
chmod -R 775 storage
chmod -R 775 bootstrap/cache
# Create the storage link for public file access
php artisan storage:link
# Verify the symlink was created
ls -la public/storage
The storage:link command creates a symbolic link from public/storage to storage/app/public, allowing uploaded files to be publicly accessible.
Step 8: Connect Your Custom Domain
Set up DNS records to point your domain to DeployBase:
# A record for root domain
Type: A
Name: @
Value: [Your DeployBase IP from the dashboard]
TTL: 3600
# CNAME for www
Type: CNAME
Name: www
Value: your-app.deploybase.io
TTL: 3600
Then update your .env:
APP_URL=https://yourdomain.com
DeployBase's free SSL certificate will be provisioned automatically once DNS propagates.
Step 9: Production Optimization
Laravel provides several built-in optimization commands for production. Run these after every deployment:
Cache Configuration, Routes, and Views
# Cache all configuration into a single file
php artisan config:cache
# Cache route definitions
php artisan route:cache
# Compile all Blade templates
php artisan view:cache
# Or run all optimizations at once
php artisan optimize
Composer Autoloader Optimization
# Generate optimized autoload files
composer install --no-dev --optimize-autoloader
Disable Debug Mode
Double-check that debug mode is off in production:
# In .env — this should ALWAYS be false in production
APP_DEBUG=false
# Verify
php artisan tinker
>>> config('app.debug');
# Should return false
>>> exit
Step 10: Deployment Workflow
For ongoing deployments, here is a reliable workflow:
Manual Deploy Script
#!/bin/bash
# deploy.sh — Run on your DeployBase server after pulling new code
set -e
echo "Pulling latest code..."
git pull origin main
echo "Installing dependencies..."
composer install --no-dev --optimize-autoloader
echo "Running migrations..."
php artisan migrate --force
echo "Clearing and rebuilding caches..."
php artisan optimize:clear
php artisan optimize
echo "Restarting queue workers..."
pm2 restart laravel-queue 2>/dev/null || true
echo "Deployment complete!"
php artisan --version
# Make executable and run
chmod +x deploy.sh
./deploy.sh
Remote Deploy from Your Local Machine
#!/bin/bash
# deploy-remote.sh — Run from your local machine
HOST="your-user@your-app.deploybase.io"
APP_DIR="~/your-laravel-app"
echo "Deploying Laravel to DeployBase..."
ssh $HOST "cd $APP_DIR && \
git pull origin main && \
composer install --no-dev --optimize-autoloader && \
php artisan migrate --force && \
php artisan optimize:clear && \
php artisan optimize && \
pm2 restart laravel-queue 2>/dev/null; true"
echo "Deploy complete."
Task Scheduling (Cron Jobs)
Laravel's task scheduler lets you define scheduled commands in app/Console/Kernel.php. To activate it in production, add one cron entry:
# Edit crontab
crontab -e
# Add this line to run Laravel's scheduler every minute
* * * * * cd /path/to/your-laravel-app && php artisan schedule:run >> /dev/null 2>&1
This single cron entry runs Laravel's scheduler, which then manages all your defined scheduled tasks — database cleanup, report generation, cache invalidation, email digests, etc.
Common Issues and Solutions
500 Internal Server Error
# Check Laravel logs
tail -50 storage/logs/laravel.log
# Common causes:
# 1. APP_KEY not set — run: php artisan key:generate
# 2. Missing .env file
# 3. Wrong file permissions on storage/
# 4. Missing PHP extensions
# Fix permissions
chmod -R 775 storage bootstrap/cache
Class Not Found Errors
# Regenerate the autoloader
composer dump-autoload --optimize
# Clear all caches
php artisan optimize:clear
Database Migration Fails
# Check migration status
php artisan migrate:status
# Check database connection
php artisan tinker
>>> DB::connection()->getPdo();
# Should show PDO object, not an error
>>> exit
# If foreign key issues, try:
php artisan migrate:fresh --force # WARNING: drops all tables
# Only use migrate:fresh on a new deployment, never on live data
Queue Workers Not Processing Jobs
# Check if the worker is running
pm2 list
# Check failed jobs
php artisan queue:failed
# Retry failed jobs
php artisan queue:retry all
# Check Redis connection
php artisan tinker
>>> Illuminate\Support\Facades\Redis::ping();
>>> exit
Security Hardening
Production Laravel applications need security attention beyond the framework defaults:
# In .env — production security settings
APP_DEBUG=false
APP_ENV=production
SESSION_SECURE_COOKIE=true
# In config/session.php or .env
SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_ENCRYPT=true
# Protect sensitive files
chmod 600 .env
chmod 600 storage/logs/laravel.log
Your Laravel App Is Live
You now have a production Laravel application running on DeployBase with:
- Laravel deployed via one-click setup with the correct PHP environment
- SSH access for Composer, Artisan, and full terminal control
- MySQL or PostgreSQL database connected and migrated
- Redis powering your cache, sessions, and job queues
- Free SSL certificate for HTTPS
- Custom domain configured
- Production optimizations applied (config/route/view caching)
- A repeatable deployment workflow for future updates
DeployBase makes Laravel hosting practical — one-click setup, SSH with Composer and Artisan on all plans, MySQL and PostgreSQL databases, Redis for queues and caching, and free SSL. Everything a Laravel application needs without the complexity of managing a bare server.
Get started with DeployBase and deploy your Laravel application today.



