A Docker-based Laravel development environment with FrankenPHP.
This project provides a complete Docker environment for running Laravel applications with FrankenPHP, which combines the Caddy web server and PHP runtime in a single process. It includes:
- Laravel application container (FrankenPHP)
- Properly configured Docker setup for local development
- Performance testing capabilities with autocannon
- Automated testing script for verification
FrankenPHP is a modern PHP application server that replaces traditional PHP-FPM setups with better performance and simpler configuration. This test bench demonstrates the benefits of using FrankenPHP for Laravel applications.
- Docker
- Docker Compose
-
Clone the repository:
git clone <repository-url> cd laravel-franken-nginx-test-bench -
Build and start the containers:
docker-compose up -d --build -
The application will be available at
http://localhost:8000 -
(Optional) HTTPS is available at
https://localhost:8443(you'll need to accept the self-signed certificate)
Note: The first build may take a few minutes as it installs all the required PHP extensions.
Dockerfile: Configuration for the Laravel application container with FrankenPHPdocker-compose.yml: Docker Compose configurationCaddyfile: Caddy server configuration for FrankenPHPdocker-entrypoint.sh: Entry point script for the application container
GET /api/hello- Returns a simple JSON response with a "Hello World" message
Run basic performance test:
autocannon http://localhost:8000/api/helloRun intensive test with 50 connections for 30 seconds:
autocannon -c 50 -d 30 http://localhost:8000/api/helloRun high-load test with 100 connections for 20 seconds:
autocannon -c 100 -d 20 http://localhost:8000/api/helloRun the automated test script to verify the setup:
bash test-frankenphp.shThe test script will:
- Check if the Docker container is running
- Verify the API endpoint is responding correctly
- Display the response from the API
The Caddyfile in this project is configured specifically for Laravel applications:
- Uses
php_serverdirective to handle PHP files directly within FrankenPHP - Includes proper routing for Laravel's front controller pattern
- Adds security headers for better application security
- Enables compression for improved performance
- Configures logging for easier debugging
- Start containers:
docker-compose up -d - Stop containers:
docker-compose down - View logs:
docker-compose logs - Check container status:
docker-compose ps
Note: Only one container (laravel_frankenphp) will be running, as FrankenPHP replaces both the Nginx and PHP-FPM containers.
FrankenPHP offers several advantages over traditional PHP-FPM setups:
-
Better Performance: FrankenPHP embeds PHP directly into the Caddy web server, eliminating the need for FastCGI protocol overhead.
-
Simpler Configuration: A single container replaces both Nginx and PHP-FPM containers, reducing complexity.
-
Built-in Features: FrankenPHP includes HTTPS, HTTP/2, HTTP/3, automatic certificates, and more out of the box.
-
Worker Mode: FrankenPHP supports a worker mode that preloads the PHP application, significantly reducing response times for Laravel applications. This is configured through the
FRANKENPHP_CONFIGenvironment variable. -
Modern Architecture: FrankenPHP is built with modern Go and PHP technologies for improved reliability and performance.
The application uses a standard Laravel .env file for configuration.
- Port mapping: 8000 (host) -> 80 (FrankenPHP container)
- Volume mapping: Current directory is mapped to
/appin the container - Worker Mode: Configured to preload Laravel application for better performance
The FrankenPHP container is configured to run in worker mode by setting the FRANKENPHP_CONFIG environment variable to worker ./public/index.php. This preloads the Laravel application, reducing the response time for subsequent requests.
The Caddy server is configured through the Caddyfile which includes:
- PHP server configuration for handling Laravel requests
- Security headers for improved security
- Compression for better performance
- Proper routing for Laravel's front controller pattern
-
500 Internal Server Error:
- Check if all required Laravel configuration files exist in the
configdirectory - Ensure proper permissions on storage directories
- Check if all required Laravel configuration files exist in the
-
Connection Refused:
- Verify that containers are running with
docker-compose ps - Check container logs with
docker-compose logs
- Verify that containers are running with
docker-compose logs --tail=20The application has been tested with autocannon and performs well under various loads:
- Requests: 477
- Latency: Average 213.96ms
- Throughput: 46.7 requests/second
- Data: 137 kB read
Note: Performance may vary based on system resources and current load.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is open source and available under the MIT License.