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.
$ php artisan migrate --force
Illuminate\Encryption\MissingAppKeyException
No application encryption key has been specified.
at vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.phpCommon 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.
cp .env.example .env
php artisan key:generate
php artisan migrate --forceClear stale caches in CI
Drop cached config/routes so artisan reads the live environment.
php artisan config:clear
php artisan cache:clear
php artisan route:clearProvide database/env for commands that need it
- Set
DB_*env vars pointing at the CI database service. - Use
--forcefor destructive commands in non-interactive CI. - Confirm with
php artisan aboutthat the environment looks right.
How to prevent it
- Generate
APP_KEYand write.envearly 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.