Setting up Laravel Octane with FrankenPHP inside a Docker environment is a great way to achieve high-performance PHP applications with asynchronous capabilities. Below is a step-by-step guide to create a Docker setup for Laravel Octane running on FrankenPHP.
What is FrankenPHP?
FrankenPHP is a high-performance PHP application server that can run PHP applications asynchronously and is compatible with frameworks like Laravel Octane.
Step 1: Prepare Laravel Project
Make sure you have a Laravel project with Octane installed:
composer require laravel/octane
php artisan octane:install
Choose roadrunner or swoole as the Octane server driver. FrankenPHP is compatible with Swoole, so:
php artisan octane:install --server=swoole
Step 2: Create Dockerfile for FrankenPHP + Laravel Octane
Create a Dockerfile in your project root:
# Use official PHP image with Swoole extension
FROM ghcr.io/frankenphp/frankenphp:latest
# Set working directory
WORKDIR /var/www/html
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
unzip \
libzip-dev \
libonig-dev \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip pdo pdo_mysql mbstring exif pcntl bcmath gd
# Copy composer and install dependencies
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Copy application files
COPY . .
# Install PHP dependencies
RUN composer install --no-dev --optimize-autoloader
# Generate optimized autoload files
RUN php artisan config:cache && php artisan route:cache && php artisan view:cache
# Expose port FrankenPHP listens on (default 8080)
EXPOSE 8080
# Run FrankenPHP with Laravel Octane
CMD ["frankenphp", "serve", "--host=0.0.0.0", "--port=8080", "--worker=octane"]
Step 3: Create frankenphp.json Configuration
FrankenPHP uses a config file to bootstrap Laravel Octane. Create frankenphp.json in your project root:
{
"server": {
"host": "0.0.0.0",
"port": 8080
},
"worker": {
"handler": "octane",
"options": {
"app_path": "/var/www/html",
"server": "swoole"
}
}
}
Step 4: Docker Compose Setup (Optional)
Create a docker-compose.yml to manage your app and database:
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
volumes:
- .:/var/www/html
environment:
- APP_ENV=local
- APP_DEBUG=true
- DB_HOST=db
- DB_PORT=3306
- DB_DATABASE=laravel
- DB_USERNAME=root
- DB_PASSWORD=root
depends_on:
- db
db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel
ports:
- "3306:3306"
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
Step 5: Build and Run
Build the Docker image:
docker-compose build
Start the containers:
docker-compose up
Your Laravel Octane app should now be accessible at http://localhost:8080.
Notes
- FrankenPHP is still evolving; check the latest docs for updates.
- You can customize the
frankenphp.json for more advanced options.
- Make sure your Laravel
.env is configured correctly for the database and cache.
- Use
php artisan octane:start locally to test before Dockerizing.
If you want me to generate a full example repo or help with specific issues, just ask!