DEV Community

Cover image for Using Frankenphp with Laravel Octane
fajar sp
fajar sp

Posted on

Using Frankenphp with Laravel Octane

The Original Post is here

in your existing laravel app, install laravel octane using this command

composer require laravel/octane
php artisan octane:install --server=frankenphp
Enter fullscreen mode Exit fullscreen mode

adjust env variable OCTANE_SERVER=frankenphp

run frankenphp with this command:

php artisan octane:frankenphp
Enter fullscreen mode Exit fullscreen mode

The octane:frankenphp command can take the following options:

  • --host: The IP address the server should bind to (default: 127.0.0.1)
  • --port: The port the server should be available on (default: 8000)
  • --admin-port: The port the admin server should be available on (default: 2019)
  • --workers: The number of workers that should be available to handle requests (default: auto)
  • --max-requests: The number of requests to process before reloading the server (default: 500)
  • --caddyfile: The path to the FrankenPHP Caddyfile file (default: stubbed Caddyfile in Laravel Octane)
  • --https: Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates
  • --http-redirect: Enable HTTP to HTTPS redirection (only enabled if –https is passed)
  • --watch: Automatically reload the server when the application is modified
  • --poll: Use file system polling while watching in order to watch files over a network
  • --log-level: Log messages at or above the specified log level, using the native Caddy logger

for deployment let's create aDockerfile

i use php 8.2 and postgres database so i need to install pgsql php
extension

FROM dunglas/frankenphp:latest-php8.2

# Install dependencies untuk Composer dan ekstensi PHP
RUN apt-get update && apt-get install -y \
    curl \
    unzip \
    libpq-dev \
    libexif-dev \
    libsodium-dev

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN install-php-extensions \
    pgsql \
    pdo_pgsql \
    gd \
    intl \
    zip \
    exif \
    sodium \
    pcntl

WORKDIR /app

COPY . ./

# Install dependencies using Composer
RUN composer install --no-dev --optimize-autoloader

RUN rm -rf ./git

# Run FrankenPHP
CMD ["php", "artisan", "octane:frankenphp", "--host=0.0.0.0", "--port=80", "--admin-port=2019"]
Enter fullscreen mode Exit fullscreen mode

lets build this image using

docker build -t app:latest .
Enter fullscreen mode Exit fullscreen mode

lets create a docker-compose.yml file

services:
    app:
        image: "app:latest"
        restart: unless-stopped
        volumes:
          - ./.env:/app/.env
Enter fullscreen mode Exit fullscreen mode

run it using

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

my use case

i use frankenphp in my personal site using laravel and filamentphp for frontend and
admin panel at https://fajar.labkita.my.id, the
speed is amazing :)

pagespeed1

pagespeed2

Reference

Canonical URL
For more detailed information, visit the original post on my blog.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay