Dockerize PHP Laravel projects with the common extensions
This is an edited clone of Sail but with PHP 8.4 version.
- Add the provided files to your project.
- Review the
Dockerfileand remove any unneeded steps to minimize the image. - Run
docker compose uporsudo docker compose up.
The artisan serve command is not designed for production environments and is better suited for development. To discourage its use, make the following adjustment:
Comment out the default PHP command that uses artisan serve:
# ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"- Enable Octane with frankenphp
For better performance, use Octane with frankenphp. Uncomment and configure the Octane-related command in your Dockerfile:
Use Octane with frankenphp for improved performance:
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=frankenphp --host=0.0.0.0 --port=80"Steps to Implement
- Install Octane in Your Laravel Application
Run the following commands:
composer require laravel/octane
php artisan octane:install
php artisan vendor:publish --tag=octane-config- Update Your Dockerfile
Configure Octane as the default PHP server:
# Set Octane as the default PHP command
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=frankenphp --host=0.0.0.0 --port=80"- Deploy the Setup
Build and start your Docker containers:
docker-compose up --buildBy following this approach, your Laravel application will leverage the performance benefits of Octane with frankenphp
Buy Me a Coffee