Skip to content
Latchkey

Laravel "artisan" Command Fails in CI - Key, Config, or Cache Issues

Laravel’s artisan boots the full framework before running a command. In CI it commonly fails because APP_KEY is unset, a cached config (bootstrap/cache/config.php) is stale, or a required env var is missing - so migrate, config:cache, or test aborts.

What this error means

A php artisan … step fails in CI with "No application encryption key has been specified", a database/env error, or behaviour from a stale cached config. The same command runs locally where .env and a generated key exist.

artisan output
$ php artisan migrate --force
   Illuminate\Encryption\MissingAppKeyException

  No application encryption key has been specified.

  at vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php

Common causes

APP_KEY is not set in CI

Laravel needs an application key for encryption. Without APP_KEY (no .env, no key:generate), boot-time providers throw MissingAppKeyException.

A stale config/route cache

A committed or leftover bootstrap/cache/*.php makes artisan read cached config that does not match the CI environment.

Missing database/env configuration

Commands like migrate need a reachable database and the right env vars; absent, they fail at boot or connection time.

How to fix it

Generate a key and set env in CI

Create an env file and an app key before running artisan.

Terminal
cp .env.example .env
php artisan key:generate
php artisan migrate --force

Clear stale caches in CI

Drop cached config/routes so artisan reads the live environment.

Terminal
php artisan config:clear
php artisan cache:clear
php artisan route:clear

Provide database/env for commands that need it

  1. Set DB_* env vars pointing at the CI database service.
  2. Use --force for destructive commands in non-interactive CI.
  3. Confirm with php artisan about that the environment looks right.

How to prevent it

  • Generate APP_KEY and write .env early in the CI job.
  • Never commit bootstrap/cache/*.php; clear caches at the start of CI.
  • Provide DB_* and other env vars artisan commands require.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →