docker-php icon indicating copy to clipboard operation
docker-php copied to clipboard

Alpine version of NGINX Unit does not exist: no PHP embed SAPI found

Open jaydrogers opened this issue 2 years ago • 3 comments

Affected Docker Images

  • *-unit-alpine

Current Behavior

When attempting to build an Alpine version of Unit, the build fails with this error:

23.87 creating build/Makefile
24.03 
24.03 Unit configuration summary:
24.03 
24.03   bin directory: ............. "/usr/bin"
24.03   sbin directory: ............ "/usr/sbin"
24.03   lib directory: ............. "/usr/lib"
24.03   include directory: ......... "/usr/include"
24.03   pkgconfig directory: ....... "/usr/share/pkgconfig"
24.03   man pages directory: ....... "/usr/share/man"
24.03   modules directory: ......... "/usr/lib/unit/debug-modules"
24.03   state directory: ........... "/var/lib/unit"
24.03   tmp directory: ............. "/var/tmp"
24.03 
24.03   pid file: .................. "/var/run/unit.pid"
24.03   log file: .................. "/dev/stdout"
24.03 
24.03   control API socket: ........ "unix:/var/run/control.unit.sock"
24.03 
24.03   non-privileged user: ....... "www-data"
24.03   non-privileged group: ...... "www-data"
24.03 
24.03   IPv6 support: .............. YES
24.03   Unix domain sockets support: YES
24.03   TLS support: ............... YES
24.03   Regex support: ............. YES
24.03   NJS support: ............... NO
24.03 
24.03   process isolation: ......... USER NS PID NET UTS CGROUP
24.03   cgroupv2: .................. YES
24.03 
24.03   debug logging: ............. YES
24.03 
24.03 + ./configure php
24.03 configuring PHP module
24.03 checking for PHP ... found
24.04  + PHP SAPI: [cli phpdbg cgi]
24.04 checking for PHP version ... not found
24.12 checking for PHP embed SAPI ... not found
24.19 
24.19 ./configure: error: no PHP embed SAPI found.

Reason why this is failing

PHP excluded embed for the Alpine versions

  • https://github.com/docker-library/php/pull/1355#issuecomment-1352087633

Expected Behavior

Unit should be able to compile and deliver an Alpine version.

Steps To Reproduce

Attempt to build an Alpine version locally:

bash scripts/dev.sh --variation unit --version 8.2.12 --os alpine

👉 Next Steps & Proposed Solution

Notes on how development works

https://serversideup.net/open-source/docker-php/docs/getting-started/contributing

Add Embed support

  • [ ] Convert the base image to use ZTS for embed support (https://github.com/docker-library/php/pull/1355#issuecomment-1352284355)

Example: https://github.com/serversideup/docker-php/pull/259/commits/358f225c1f3a87d5b909c4ba10a21d6f855336e3

Update installer to support Debian and Alpine

https://github.com/serversideup/docker-php/blob/aa4ad4416cc9168a9baa265f0419a3fd0b53e622/src/variations/unit/Dockerfile#L21-L60

  • [ ] Break the scripts into two separate files
  • [ ] Load the script based on the OS installing

Features to support

  • [ ] Compile NGINX Unit from source with the provided PHP version from the base image
  • [ ] Enable the copying of unitd for "production use"
  • [ ] Enable the copying of unitd-debug for debug use

Important notes on current functionality

  • We will continue to use the "Docker CMD Override" currently in place

https://github.com/serversideup/docker-php/blob/main/src/variations/unit/etc/entrypoint.d/10-init-unit.sh#L192

Validating functionality

  • [ ] Ensure 8.3.12 works with bookworm
bash scripts/dev.sh --variation unit --version 8.3.13 --os bookworm
  • [ ] Ensure 8.3.12 works with alpine
bash scripts/dev.sh --variation unit --version 8.3.13 --os  alpine
  • [ ] Ensure 7.4.33 works with bullseye
bash scripts/dev.sh --variation unit --version 7.4.33 --os bullseye
  • [ ] Ensure 7.4.33 works with alpine
bash scripts/dev.sh --variation unit --version 7.4.33 --os  alpine

jaydrogers avatar Nov 30 '23 16:11 jaydrogers

Also have the same problem

beeyev avatar Dec 03 '23 21:12 beeyev

EDIT 2

Sorry, now I see you use the official php image as the base image.

But the php zts build includes SAPI: https://github.com/docker-library/php/blob/6c4b77d14c604deefd63fd6d39133f9a1f7a83c3/8.3/alpine3.18/zts/Dockerfile#L166


EDIT

Now I see that you build it from source code, I don't know if you've tried it yet, but there is such an option: ./configure --enable-embed


This is what I used when I first tried with the nginx unit, it's not perfect, but maybe it helps. I haven't dealt with it since then, maybe SAPI has been removed from it since then.

FROM alpine:3.14

# Install packages and remove default server definition
RUN apk --no-cache add php7 php7-zip php7-intl php7-opcache php7-json php7-openssl php7-curl php7-tokenizer php7-exif php7-pcntl \
    php7-zlib php7-xml php7-phar php7-dom php7-xmlreader php7-ctype php7-session php7-fileinfo php7-pdo_mysql \
    php7-mbstring php7-gd php7-bcmath php7-gd php7-mcrypt php7-iconv unit unit-openrc unit-php7 curl \
    git \
    libpng-dev \
    libxml2-dev \
    zip \
    unzip \
    && ln -sf /dev/stdout /var/log/unit.log \
    && ln -sf /dev/stdout /var/log/access.log

# Configure unit
COPY docker/nginx-unit/config.json /var/lib/unit/conf.json

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Make sure files/folders needed by the processes are accessable when they run under the unit user
RUN mkdir -p /.composer && \
    mkdir -p /run/php && \
    mkdir -p /var/www && \
    chown -R unit:unit /var/www && \
    chown -R unit:unit /.composer

# Set working directory
WORKDIR /var/www

# install all PHP dependencies
COPY --chown=unit src/composer.lock .
COPY --chown=unit src/composer.json .
RUN composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader

# Add application
COPY --chown=unit src/ .

COPY --chown=unit ./docker/.env ./.env

RUN composer dump-autoload

RUN php artisan optimize && php artisan config:cache && php artisan route:cache

EXPOSE 8080

CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"]

# TODO: Implement HEALTHCHECK
# HEALTHCHECK --interval=5s --timeout=3s CMD curl --fail http://localhost/fpm-ping || exit 1

draxvint avatar Dec 06 '23 22:12 draxvint

Thanks for posting your solution @draxvint.

Update on this issue

I just got off the call with the extremely helpful and knowledgeable @tippexs from the NGINX Unit team.

Timo will be helping us out on getting a solution here: https://github.com/serversideup/docker-php/pull/259

Stay tuned 😃

jaydrogers avatar Dec 08 '23 16:12 jaydrogers

Closing this issue because NGINX Unit has been archived and is no longer maintained by the NGINX team: https://github.com/nginx/unit?tab=readme-ov-file#nginx-unit

jaydrogers avatar Oct 13 '25 13:10 jaydrogers