Search code examples
phpdockercompilation

Fnankenphp compiling for xdebug support


Im trying to build frankenphp so I can have xdebug in my dev environment.

Im trying to half follow this https://frankenphp.dev/docs/compile/ compile guide. The difference is that Im not compiling php from scratch, not sure if thats the issue.

Currently Im hitting this error -

48.49 # github.com/dunglas/frankenphp/caddy/frankenphp
48.49 /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
48.49 /usr/bin/ld: cannot find -lphp: No such file or directory
48.49 collect2: error: ld returned 1 exit status

And here is the docker file im using -

FROM ubuntu:22.04

ARG WWWGROUP
WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Base
RUN apt-get update \
        && mkdir -p /etc/apt/keyrings \
        && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch nginx cron tar build-essential \
                      libbrotli-dev libsodium-dev libargon2-dev libxml2-dev bison re2c pkg-config libssl-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libsqlite3-dev libonig-dev

# PHP
RUN curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
    && echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
    && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/keyrings/pgdg.gpg >/dev/null \
    && echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
    && apt-get update \
    && apt-get install -y php8.3 php8.3-cli php8.3-dev \
       php8.3-pgsql php8.3-sqlite3 php8.3-gd \
       php8.3-curl \
       php8.3-imap php8.3-mbstring \
       php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \
       php8.3-intl php8.3-readline \
       php8.3-ldap \
       php8.3-msgpack php8.3-igbinary php8.3-redis \
       php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug \
    && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
    && apt-get install -y postgresql-client-$POSTGRES_VERSION

# Go lang for frankenphp
RUN curl -LO https://golang.org/dl/go1.22.0.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

ENV PATH=$PATH:/usr/local/go/bin
ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin

# Frankenphp
RUN curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz \
    && cd frankenphp-main/caddy/frankenphp \
    && CGO_CFLAGS="$(php-config --includes)" CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build

This is a cutdown version of laravel sail docker, as I dont feel like everything that comes after this is revelant.

What I tried adding is -L/usr/lib/php/20230831 -lphp to CGO_LDFLAGS, in hopes that that would fix the issue, but it dosnt. I went digging in the container and it seems like there is no libphp. So thats maybe the issue? But I cant really find any info of what I should add extra to "install" it. As fas as Im aware, php8.3-dev should add it?


Solution

  • In order to compile FrankenPHP, you must compile php with --enable-ZTS yourself, or use the supplied docker file to build it (which builds php + extensions itself).