oerdnj / deb.sury.org

Public bugreports for anything ppa:ondrej/*
832 stars 26 forks source link

[Feature suggestion] PHP language module for Nginx Unit #1302

Open Articus opened 4 years ago

Articus commented 4 years ago

Is your feature request related to a problem? Please describe.

About two years ago Nginx team introduced Nginx Unit - their own application server that can run PHP applications via libphp-embed. We use it in production for more than a year now (nearly year and a half) and it seems to be a perfect alternative for PHP-FPM: feature parity for web applications with only one entry script, better performance, more convenient configuration.

Nginx Unit has official repository and its installation is pretty straightforward but there is one "catch" - unit-php (package for PHP language module) is build for PHP package from official Debian repository. So for example if you want to run Nginx Unit + PHP 7.4 even on Buster, you have to build PHP language module from source :(

Describe the solution you'd like

According discussion at Nginx Unit issue tracker the best place for custom package with PHP language module would be the repository that provides custom PHP package. And for example popular PHP package repository for Centos does that.

I know that is a lot to ask for but would you be interested in providing similar packages? My personal "dream come true" variant would be:

Describe alternatives you've considered

There seems to be only two alternatives:

P. S.

Regardless of the answer great thanks for maintaining the best Debian PHP repo!

Articus commented 3 years ago

Small update: now there is one more alternative - https://github.com/Articus/unit-php (a bit "hackish" proof-of-concept I made for our project migration to PHP 8.0).

razvanphp commented 3 months ago

I actually managed to easily compile this for sury php7.4 on bookworm using the instructions here: https://unit.nginx.org/howto/modules/#modules-pkg

This is even easier when done in a temporary docker builder stage.

It would be nice to have those packages to be honest. Thank you for your work!

oerdnj commented 3 months ago

It would be nice, but I don’t have capacity to do that and maintain yet another framework.

razvanphp commented 3 months ago

just for posterity, I managed to get this working in docker.

First, start from your favourite distro, install nginx unit from apt/rpm, sury embed package, compile unit-php in a separate stage and copy .so file in the end-image.

FROM debian:bullseye-slim AS base

RUN apt-get update \
    && apt-get upgrade \
    && apt-get install \
        apt-transport-https \
        ca-certificates \
        lsb-release \
        software-properties-common \
        curl \
        libcurl4-gnutls-dev \
        git \
        unzip

# add repository for Ondřej Surý's PHP packages
RUN curl -s https://packages.sury.org/php/apt.gpg > /etc/apt/trusted.gpg.d/php.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/php.list

RUN apt-get update \
    && apt-get install \
        php8.0-cli \
        php8.0-curl \
        php8.0-zip \
        php8.0-bcmath \
        php8.0-mbstring \
        php8.0-gd \
        php8.0-intl \
        php8.0-opcache \
        php8.0-pdo-mysql \
        libphp8.0-embed

# add official nginx unit repo
RUN curl -fsSL https://unit.nginx.org/keys/nginx-keyring.gpg | apt-key add - \
    && add-apt-repository -s "deb https://packages.nginx.org/unit/debian/ $(lsb_release -cs) unit"

RUN apt-get update \
    && apt-get install \
        unit \
    && ln -sf /dev/stdout /var/log/unit.log

# COPY ./docker/*.pem  /docker-entrypoint.d/
COPY ./docker/*.json /docker-entrypoint.d/
COPY ./docker/*.sh   /docker-entrypoint.d/
COPY ./docker/docker.entrypoint /usr/local/bin/docker-entrypoint.sh

WORKDIR /web

STOPSIGNAL SIGTERM

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
EXPOSE 80
CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"]

###########################################################
FROM base as unit-builder

RUN apt-get update && \
    apt-get install -y \
        curl \
        build-essential \
        libssl-dev \
        libpcre3-dev \
        zlib1g-dev \
        php8.0-dev

# https://unit.nginx.org/howto/modules/#modules-pkg
RUN unitd --version > /tmp/unit_version_output.txt 2>&1 && \
    UNIT_VERSION=$(grep "unit version:" /tmp/unit_version_output.txt | awk '{print $3}') && \
    UNIT_CONFIGURE_PARAMS=$(grep "configured as" /tmp/unit_version_output.txt | cut -d' ' -f4- | sed "s/--ld-opt='[^']*'//g" | sed "s/--njs//g" | tr -s ' ') && \
    echo "Compiling for Unit [${UNIT_VERSION}] with stripped configure parameters: ${UNIT_CONFIGURE_PARAMS}" && \
    mkdir -p /unit-src && \
    curl -L -o /unit-src/unit.tar.gz https://sources.nginx.org/unit/unit-${UNIT_VERSION}.tar.gz && \
    tar xzf /unit-src/unit.tar.gz -C /unit-src && \
    cd /unit-src/unit-${UNIT_VERSION} && \
    eval "./configure $UNIT_CONFIGURE_PARAMS" && \
    ./configure php --module=php8.0 --config=php-config && \
    make php8.0 && \
    ls -al build/lib/unit/modules/

###########################################################
FROM base AS dev

COPY --from=composer:2.5.5 /usr/bin/composer /usr/bin/composer
COPY --from=unit-builder /unit-src/unit-*/build/lib/unit/modules/php8.0.unit.so /usr/lib/unit/modules/