Skip to main content
Adzbyte Solutions
Web Development

Protect Laravel Config Cache During Deployment

Adrian Saycon
Adrian Saycon
November 24, 20265 min read
Protect Laravel Config Cache During Deployment

Protecting .env is only part of protecting a Laravel deployment. Once configuration is compiled, another file can contain the environment’s credentials and application key. That file needs to be considered when setting permissions and deciding what leaves a build job.

In my deployment protection change for AdzByte App, I tightened handling of bootstrap/cache/config.php. The preceding deployment workflow work shows how that file reaches the release bundle. I changed the rules checked before a release is promoted.

Include compiled configuration in the file review

Laravel’s configuration-caching documentation explains that cached configuration changes how the application loads its settings. In this application, the deployment script explicitly treats the compiled configuration as credential-bearing output.

That makes the file different from an ordinary disposable asset cache. It may be safe to rebuild, but a copy still needs protection while it exists. Being generated doesn’t mean its contents are public.

The after-pull script already checks that .env is a real file rather than a symlink and sets its permissions to owner read and write. The update extends that attention to the compiled configuration instead of assuming the original environment file is the only sensitive copy.

For another application, I’d list the generated outputs that can contain resolved settings: configuration caches, generated manifests, debug dumps, and deployment backups where applicable. Each needs a decision about readers, storage, and copying.

Set creation permissions before generating the file

The script uses a normal creation mask while installing production dependencies, then switches to a restrictive mask before migrations and optimization. It also tightens an existing compiled configuration file before proceeding and sets the resulting file to mode 0600 after optimization.

The order is worth noticing. Fixing permissions only after generation can leave an unnecessary interval with broader access. Protecting the previous file also matters when a deployment starts from an older cache with different permissions.

On the Unix deployment this targets, 0600 permits the owner to read and write the file without granting group or other access. That assumes the runtime has the correct ownership arrangement. Applying the same command to a different host without checking its process users can break the application.

The goal is a permission policy that fits the runtime, followed by an explicit check. Copying a mode value without understanding who needs to read the file isn’t enough.

Verify the generated result before calling it ready

The server verifier requires the compiled configuration to exist, rejects a symlink at that location, and checks the final file mode. This turns the protection from an intended shell command into a release condition.

That matters because scripts change. Someone can move optimization earlier, add a new generator, or restore a file with inherited permissions. The verifier checks the resulting state instead of trusting that every earlier step behaved as expected.

The check is deliberately narrow. It doesn’t prove the web server can never expose an internal path, and it doesn’t protect against another process running as the same owner. Correct document-root configuration, access controls, and the handling of copied files remain separate concerns.

I’d keep those limits visible in a deployment review. A successful permission assertion supports a useful claim about this file; it isn’t a certificate for the whole server.

Promote the public build, not the whole working tree

The CI job runs production cache generation as a verification step. Its uploaded artifact, however, is limited to public/build. The deployment workflow downloads that named artifact into the same path and adds that path to the deployment branch.

Those are two different purposes inside one pipeline: validate that production setup works, and carry the frontend assets needed by the release. The compiled configuration doesn’t need to travel with the public build just because CI created it.

This is a useful review point for artifact changes. Replacing a narrow path with the repository root can include generated files that were never meant to leave the runner. Ignored Git files can still be captured by an artifact upload with a broader selection.

Limiting the artifact doesn’t prove that no secret could enter a frontend bundle. Application code and build plugins can still publish values. It does remove an unnecessary route for copying the server’s compiled configuration.

Test the permission transition with disposable files

The deployment test creates an existing compiled configuration fixture with broader permissions. Its synthetic optimization command writes a replacement. After the deployment script runs, the test checks that the final configuration has the protected mode.

The same orchestration test checks that the environment file’s contents and the stored customer fixture survive. It uses disposable Git history and stubbed PHP, Composer, and HTTP behavior to exercise the sequence safely.

That scope matters when describing the evidence. The test demonstrates how the deployment script handles these files and failure points. A stubbed optimization command isn’t proof of every Laravel runtime detail or every hosting permission arrangement.

The CI workflow runs the deployment-safety test suite, and later qualification records its passing result. A later deployment still needs its own checks.

Keep sensitive output tied to its environment

The practical lesson from this change is to follow resolved configuration beyond its source file. Check how it’s generated, which user can read it, whether a verifier enforces the result, and whether any artifact or backup carries another copy.

For this workflow, the public asset artifact stays narrow and the server creates its protected configuration in place. That gives the deployment a clear rule to maintain: generated configuration is rebuildable, but it still deserves the same careful handling as the settings it contains.

Adrian Saycon

Written by

Adrian Saycon

A developer with a passion for emerging technologies, Adrian Saycon focuses on transforming the latest tech trends into great, functional products.

Discussion (0)

Your email is used only for comment moderation and is never published.

No comments yet. Be the first to share your thoughts.