Deploying Laravel to Vercel

How to set up and deploy our Laravel application on a serverless environment called Vercel, including automated deployments and previews with out any cost.
Inspired by Caleb Porzio

Configuration for Vercel

api/index.php

<?php
require __DIR__ . '/../public/index.php';

Vercel only allows an app’s entry-point to live inside the API directory, so we have to set up a simple script to forward to Laravel’s normal public/index.php entry-point.

.vercelignore

/vendor

This will make sure we don’t upload the entirety of our vendor directory to Vercel when we deploy (We’ll set up Vercel to automatically install composer dependencies).

vercel.json

{
    "version": 2,
    "framework": null,
    "functions": {
        "api/index.php": { "runtime": "[email protected]" }
    },
    "routes": [{
        "src": "/(.*)",
        "dest": "/api/index.php"
    }],
    "env": {
        "APP_ENV": "production",

        "APP_CONFIG_CACHE": "/tmp/config.php",
        "APP_EVENTS_CACHE": "/tmp/events.php",
        "APP_PACKAGES_CACHE": "/tmp/packages.php",
        "APP_ROUTES_CACHE": "/tmp/routes.php",
        "APP_SERVICES_CACHE": "/tmp/services.php",
        "VIEW_COMPILED_PATH": "/tmp",

        "CACHE_DRIVER": "array",
        "LOG_CHANNEL": "stderr",
        "SESSION_DRIVER": "cookie"
    }
}

Sources

Published