Back to Blog
Tutorial

How to Deploy a Laravel Application in 1 Minute

Daniel Brooks6 min read
How to Deploy a Laravel Application in 1 Minute

Laravel is PHP's most popular framework, powering applications from small startups to large-scale platforms. Deploying Laravel to production requires proper environment configuration, queue workers, scheduled tasks, and storage setup.

With Out Plane, you can deploy your Laravel application in under a minute. This guide shows you exactly how.

What You'll Need

Before starting, make sure you have:

  • PHP 8.3+ installed on your machine
  • Composer installed globally
  • A GitHub account
  • A Laravel application in a GitHub repository

Don't have PHP installed? Here's how to install it:

  • Windows: Download from windows.php.net or use Laragon for a full local environment
  • macOS: Use brew install php to install the latest version
  • Linux: Run sudo apt install php php-cli php-mbstring php-xml php-curl php-zip (Ubuntu/Debian) or sudo dnf install php php-cli php-mbstring php-xml (Fedora)

Install Composer from getcomposer.org if you don't have it yet.

Once PHP and Composer are installed, create a new Laravel application:

bash
composer create-project laravel/laravel my-laravel-app
cd my-laravel-app

If you don't have a Laravel app yet, use our example below.

Quick Start: Sample Laravel Application

Create a new Laravel project:

bash
composer create-project laravel/laravel my-laravel-app
cd my-laravel-app

The default Laravel installation includes a welcome page. Let's add a simple API endpoint.

Update routes/web.php:

php
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return response()->json([
        'message' => 'Hello from Laravel!',
        'status' => 'running',
    ]);
});

Route::get('/health', function () {
    return response()->json(['status' => 'healthy']);
});

Add an API route in routes/api.php:

php
<?php

use Illuminate\Support\Facades\Route;

Route::get('/info', function () {
    return response()->json([
        'framework' => 'Laravel',
        'php_version' => PHP_VERSION,
        'environment' => config('app.env'),
    ]);
});

Test your application locally:

bash
php artisan serve

Visit http://localhost:8000 in your browser. You should see the JSON response.

Add a Dockerfile

Create a Dockerfile in your project root:

dockerfile
FROM php:8.3-cli

RUN apt-get update && apt-get install -y \
    git \
    unzip \
    libpq-dev \
    libzip-dev \
    && docker-php-ext-install pdo pdo_pgsql zip bcmath \
    && rm -rf /var/lib/apt/lists/*

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /app

COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts

COPY . .

RUN composer dump-autoload --optimize \
    && php artisan config:clear \
    && php artisan route:clear \
    && php artisan view:clear

RUN chmod -R 775 storage bootstrap/cache

EXPOSE 8080

CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8080"]

This uses php artisan serve for simplicity. For higher traffic applications, consider using Nginx with PHP-FPM or FrankenPHP for better concurrency.

Push this code to a GitHub repository, and you're ready to deploy.

Deploy in 3 Steps

Step 1: Connect Your Repository

  1. Go to console.outplane.com
  2. Sign in with your GitHub account
  3. Select your Laravel repository from the list

Step 2: Configure Your Application

Configure the following settings in the create application form:

Build Method

Select Dockerfile as your build method since the repository includes a Dockerfile.

Basic Settings

  • Port: Set to 8080
  • Branch: Select main or your preferred branch
  • Region: Choose the region closest to your users

Environment Variables (Required)

Laravel requires certain environment variables for production. Add these using the Add button or Raw Edit:

text
APP_KEY=base64:your-generated-app-key-here
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-app.outplane.app
LOG_CHANNEL=stderr
DB_CONNECTION=pgsql

Generate a secure APP_KEY with:

bash
php artisan key:generate --show

This outputs a base64:... string. Copy it as the value for APP_KEY.

Step 3: Deploy

Click Deploy Application and watch the build process:

  1. Queued → Waiting for resources
  2. Building → Installing Composer dependencies, optimizing autoloader
  3. Deploying → Starting your Laravel application
  4. Ready → Your app is live

Once the status shows Ready, your application is live. You can find your application URL at the top of the deployment page. Click the URL to open your Laravel app in a new tab. SSL is automatically configured.

Production Best Practices

APP_KEY Generation

Every Laravel application requires an APP_KEY for encryption. Never reuse keys across environments:

bash
php artisan key:generate --show

Set this value as the APP_KEY environment variable. Without it, Laravel will throw a runtime exception.

Config and Route Caching

Speed up your application by caching configuration and routes. Add these commands to your Dockerfile:

dockerfile
RUN php artisan config:cache \
    && php artisan route:cache \
    && php artisan view:cache

Note that config:cache bakes environment variables into the cache at build time. If you use env() calls outside of config files, those values will not be available. Always reference configuration values with config() instead.

Storage Permissions

Laravel writes to the storage and bootstrap/cache directories. Ensure they are writable:

dockerfile
RUN chmod -R 775 storage bootstrap/cache

If your application uses file uploads, configure a cloud storage driver like S3 instead of local disk.

If your application serves files from storage/app/public, create the symbolic link in your Dockerfile:

dockerfile
RUN php artisan storage:link

Queue Workers

For applications that use Laravel's queue system, run a separate worker process. You can deploy a second service on Out Plane with the same repository and a different start command:

text
php artisan queue:work --tries=3 --timeout=90

Set the QUEUE_CONNECTION environment variable to database or redis depending on your driver.

Connecting a Database

Most Laravel applications need a database. Out Plane provides managed PostgreSQL:

  1. Go to Databases in the sidebar
  2. Click Create Database
  3. Select PostgreSQL version and region
  4. Copy the connection details

Add the database configuration as environment variables:

text
DB_CONNECTION=pgsql
DB_HOST=your-database-host
DB_PORT=5432
DB_DATABASE=your-database-name
DB_USERNAME=your-database-user
DB_PASSWORD=your-database-password

Alternatively, use a single DATABASE_URL environment variable if your Laravel application is configured to parse it.

After connecting, run migrations by adding an entrypoint script or running them as a one-off command:

bash
php artisan migrate --force

The --force flag is required in production to bypass the confirmation prompt.

Custom Domain Setup

Replace the default .outplane.app URL with your own domain:

  1. Navigate to Domains
  2. Click Map Domain
  3. Enter your domain (e.g., app.yourdomain.com)
  4. Add the DNS records shown to your domain registrar

Update the APP_URL environment variable to match your new domain:

text
APP_URL=https://app.yourdomain.com

SSL certificates are automatically provisioned once DNS propagates.

Monitoring Your Application

After deployment, monitor your Laravel application:

  • Logs: View real-time application logs. Set LOG_CHANNEL=stderr so Laravel writes logs to standard error, which Out Plane captures automatically.
  • Metrics: Track CPU, memory, and network usage
  • HTTP Logs: Analyze incoming requests, response times, and status codes

Access these from the sidebar in your application dashboard.

For application-level logging, Laravel's built-in logging with the stderr channel works seamlessly:

php
// config/logging.php is already configured for stderr
// Just use the Log facade anywhere in your application
use Illuminate\Support\Facades\Log;

Log::info('Order processed', ['order_id' => $order->id]);
Log::error('Payment failed', ['error' => $exception->getMessage()]);

Troubleshooting

APP_KEY Missing or Invalid

Generate a new key and set it as an environment variable. Without a valid APP_KEY, Laravel cannot encrypt sessions, cookies, or any other data:

bash
php artisan key:generate --show

Copy the output and set it as the APP_KEY environment variable in your application settings.

Storage Permission Errors

Ensure storage directories are writable. Add this to your Dockerfile:

dockerfile
RUN chmod -R 775 storage bootstrap/cache

If errors persist, check that no files were copied with restrictive permissions from your local environment.

500 Internal Server Error

Check your application logs. Navigate to Logs in the sidebar. Common causes:

  • Missing APP_KEY environment variable
  • Database connection failures
  • Missing PHP extensions (pdo_pgsql, mbstring, xml)
  • Cached configuration referencing unavailable environment variables

Migration Failures

Verify database connectivity. Ensure your DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD environment variables are set correctly. Test the connection:

bash
php artisan db:monitor

Session and Cache Driver Issues

Use database or Redis drivers in production. The default file driver does not work reliably in containerized environments. Update these environment variables:

text
SESSION_DRIVER=database
CACHE_STORE=database

Or use Redis if available:

text
SESSION_DRIVER=redis
CACHE_STORE=redis
REDIS_HOST=your-redis-host
REDIS_PORT=6379

Run php artisan session:table && php artisan migrate if using the database driver.

Next Steps

Your Laravel application is now deployed and running in production. Here's what to explore next:

  • Scale your application: Adjust instance types and auto-scaling settings for higher traffic
  • Set up CI/CD: Enable automatic deployments on every git push
  • Add Redis: Use Redis for queues, cache, and session storage for better performance
  • Configure scheduled tasks: Run Laravel's task scheduler with php artisan schedule:work

Summary

Deploying a Laravel application to Out Plane takes three steps:

  1. Connect your GitHub repository
  2. Configure port (8080), APP_KEY, and environment variables
  3. Deploy and get your live URL

No server configuration, no manual SSL setup, no infrastructure management. Just push your code and go live.

Ready to deploy your Laravel application? Get started with Out Plane and receive $20 in free credit.


Tags

laravel
php
deployment
tutorial
web-framework

Start deploying in minutes

Connect your GitHub repository and deploy your first application today. $20 free credit. No credit card required.