Customizing Laravel Vapor: Extensions, Binaries, and PHP Runtime
Overview
offers a robust serverless experience, but default environments often lack the specific tools required for media processing or specialized arithmetic. By leveraging Docker-based deployments, we can step beyond the standard runtime limitations. This tutorial demonstrates how to modify your Dockerfile to inject custom binaries like , install specialized extensions, and override core configuration settings.
Prerequisites
To follow along, you should be familiar with:
- Basic concepts (images, layers, and containers).
- development and extension management.
- deployment workflows.
- package management (
apk).
Key Libraries & Tools
- : The lightweight security-oriented distribution used as the base for Vapor images.
- : A complete solution to record, convert, and stream audio and video.
- : Command-line utilities for interacting with MySQL databases.
- GMP Extension: The GNU Multiple Precision library for working with arbitrary-length integers in PHP.
Installing System Binaries
Since Vapor’s Docker images use , we use the apk package manager. If your application needs to process video or connect to databases via the CLI, you must add these to your Dockerfile manually.
RUN apk --update add \
ffmpeg \
mysql-client
Always include the --update flag to ensure you are pulling the latest metadata from the Alpine repositories before the installation begins.
Compiling PHP Extensions
PHP extensions like gmp often require underlying system headers. If you attempt to install an extension without its dependency, the build will fail during the compilation phase. To fix this, install the development library (-dev) before running the helper script.
# Install the system dependency first
RUN apk add --no-cache gmp-dev
# Use the helper to compile and enable the extension
RUN docker-php-ext-install gmp
Customizing php.ini Overrides
Sometimes you need to increase max_input_vars or adjust memory limits. Instead of modifying the base image, create a local php.ini and copy it into the specific directory where PHP scans for additional configurations.
COPY php.ini /usr/local/etc/php/conf.d/overrides.ini
Syntax Notes & Best Practices
- Layer Optimization: Combine multiple
apk addcommands into a singleRUNinstruction to keep image sizes small. - No-Cache: Use
apk add --no-cacheto avoid storing the package index locally, further reducing the image footprint. - Location Matters: In Vapor images, the configuration directory is strictly located at
/usr/local/etc/php/conf.d/.
Tips & Gotchas
- Compilation Failures: If
docker-php-ext-installfails, check the logs for missing.hfiles. This usually indicates a missing-devpackage in Alpine. - Deployment Sync: Remember that changes to the
Dockerfilerequire a freshvapor deployto rebuild the image and propagate changes to the cloud environment.
- 25%· products
- 17%· products
- 17%· products
- 17%· products
- 8%· products
- Other topics
- 17%

Learn Laravel Vapor #25: Customizing Docker based environments
WatchLaravel // 7:12
The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.