Skip to content

dockerize php laravel or lumen projects with the common extensions

License

Notifications You must be signed in to change notification settings

islamsamy214/dockerize-laravel-lumen

Repository files navigation

Laravel Lumen in Docker

Dockerize PHP Laravel or Lumen projects with the common extensions

Introduction

This is an edited clone of Sail but with PHP 8.3 version.

How to Use

  1. Add the provided files to your project.
  2. Review the Dockerfile and remove any unneeded steps to minimize the image.
  3. Run docker compose up or sudo docker compose up.

Optimal Configuration

1. Avoid Using artisan serve

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"
  1. Enable Octane with Swoole

For better performance, use Octane with Swoole. Uncomment and configure the Octane-related command in your Dockerfile:

Use Octane with Swoole for improved performance:

ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port=80"
  1. Set Up Nginx as a Reverse Proxy

Nginx will act as the proxy server, handling all incoming requests and forwarding them to Octane. This setup ensures you get maximum performance from Octane with Swoole.


Steps to Implement

  1. Install Octane in Your Lumen Application

Run the following commands:

composer require laravel/octane  
php artisan octane:install  
php artisan vendor:publish --tag=octane-config
  1. 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=swoole --host=0.0.0.0 --port=80"
  1. Configure Nginx

Use Nginx to forward traffic to Octane.

  1. Deploy the Setup

Build and start your Docker containers:

docker-compose up --build

By following this approach, your Laravel Lumen application will leverage the performance benefits of Octane with Swoole, while Nginx acts as the reverse proxy to handle incoming traffic efficiently.


Buy Me a Coffee

https://www.buymeacoffee.com/islamsamy

About

dockerize php laravel or lumen projects with the common extensions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published