dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.64k stars 218 forks source link

Enabling/adding PHP extensions #138

Closed jasonmccallister closed 1 year ago

jasonmccallister commented 1 year ago

What is the best way to add PHP extensions? Once approach I enjoy from Bref is how it includes the extensions but disables them. Are there plans to include enabling/disabling extensions like Postgres?

jasonmccallister commented 1 year ago

I did a little bit of code diving into the container build (Dockerfile) and saw the image ships with mlocati/docker-php-extension-installer. So I wrapped the dunglas/frankenphp image with my own Dockerfile:

FROM dunglas/frankenphp
RUN apt-get update -y && rm -rf /var/lib/apt/lists/*
RUN install-php-extensions pdo_pgsql
COPY Caddyfile /etc/Caddyfile

Then I made a docker-compose.yaml file with the following:

version: "3.7"
services:
  postgres:
    image: postgres:15
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - db_data:/var/lib/postgresql/data
  app:
    image: my-image
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - ./:/app
      - ./Caddyfile:/etc/Caddyfile # really only used to tweak/override the Caddy config for development
    environment:
      SERVER_NAME: ":8000" # override the Caddyfile to use a port instead of a domain
    env_file: .env
volumes:
  db_data:
dunglas commented 1 year ago

That's indeed the way to go!