Skip to content

Instantly share code, notes, and snippets.

@Victor-Fiamoncini
Created October 1, 2024 19:57
Show Gist options
  • Save Victor-Fiamoncini/95a010a68c1686650dfe282d5dffb500 to your computer and use it in GitHub Desktop.
Save Victor-Fiamoncini/95a010a68c1686650dfe282d5dffb500 to your computer and use it in GitHub Desktop.
Franken PHP Dockerfile
# Base image with PHP and FrankenPHP
FROM dunglas/frankenphp:1-php8.3 AS frankenphp
RUN apt-get update && apt-get install -y zip libzip-dev libpq-dev libicu-dev wget acl curl
RUN docker-php-ext-install sockets zip
RUN docker-php-ext-configure zip
RUN docker-php-ext-install pgsql pdo_pgsql intl
ENV SERVER_NAME my_app
ENV FRANKENPHP_CONFIG "worker ./public/index.php"
ENV APP_RUNTIME Runtime\\FrankenPhpSymfony\\Runtime
# Set working directory
WORKDIR /my_app/app
COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer
# Copy composer files and install dependencies
COPY composer.json composer.lock ./
RUN composer install --no-scripts --no-interaction --no-autoloader --no-ansi
RUN composer dump-autoload --optimize --no-ansi && composer clear-cache --no-ansi
# Copy Symfony app files
COPY . .
# Define the build argument (DATABASE_URL) to build Symfony cache
ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}
RUN php bin/console cache:warmup
# Copy Caddyfile for configuration
COPY ./Caddyfile /etc/caddy/Caddyfile
# Expose port 80
EXPOSE 80
# Run FrankenPHP with Caddy configuration
CMD frankenphp run --config /etc/caddy/Caddyfile
@Victor-Fiamoncini
Copy link
Author

Victor-Fiamoncini commented Oct 1, 2024

Used Caddyfile

Basic config for Caddy server with FrankenPHP

{
    # Enables Frankenphp
    frankenphp
}

:80 {
    # Sets root directory
    root * /my_app/app/public

    # Enables compression
    encode gzip

    # Executes PHP files in the current directory and serve assets
    php_server

    # Enables logging to stdout
    log {
        output stdout
        format filter {
            request>remote_ip delete
            request>remote_port delete
            request>client_ip delete
            request>proto delete
            request>host delete
            request>headers delete
            bytes_read delete
            user_id delete
            resp_headers delete
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment