nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.38k stars 324 forks source link

Error when using php version 8 #515

Closed porozhnyy closed 1 year ago

porozhnyy commented 3 years ago

Hello! When installing php version 8, the following error occurs in the logs:

curl -X PUT --data-binary @/tmp/unit.json --unix-socket /var/run/control.unit.sock http://localhost/config/
{
        "error": "Invalid configuration.",
        "detail": "The module to run \"php\" is not found among the available application modules."
}
cat /var/log/unit.log 
2020/12/30 07:46:28 [info] 12#12 discovery started
2020/12/30 07:46:28 [alert] 12#12 dlopen("/usr/lib/unit/modules/php.unit.so"), failed: "libphp7.so: cannot open shared object file: No such file or directory"
 ls -l /usr/lib/libphp*
lrwxrwxrwx 1 root root      12 Dec 29 19:15 /usr/lib/libphp.so -> libphp8.0.so
-rw-r--r-- 1 root root 4793816 Nov 27 12:26 /usr/lib/libphp8.0.so
lrwxrwxrwx 1 root root      25 Dec 29 19:15 /usr/lib/libphp8.so -> /etc/alternatives/libphp8

Steps to reproduce:

Dockerfile

FROM ubuntu:20.04

WORKDIR /app

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
    && apt-get install -y gnupg curl ca-certificates zip unzip git supervisor mysql-client \
    && mkdir -p ~/.gnupg \
    && chmod 600 ~/.gnupg \
    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
    && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list
RUN apt-get update \
    && apt-get install -y php8.0-cli php8.0-curl php8.0-gd php8.0-mysql php8.0-mbstring php8.0-xml php8.0-zip php8.0-bcmath \
        php8.0-intl php8.0-readline php8.0-msgpack php8.0-igbinary php8.0-redis libphp8.0-embed \
    && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add - \
    && echo "deb https://packages.nginx.org/unit/ubuntu/ focal unit" > /etc/apt/sources.list.d/unit.list \
    && apt-get update \
    && apt-get install -y unit unit-php \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY ./docker/php/unit.json /tmp/unit.json

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

{
    "listeners": {
        "*:80": {
            "pass": "routes/laravel"
        }
    },

    "routes": {
        "laravel": [
            {
                "match": {
                    "uri": "!/index.php"
                },
                "action": {
                    "share": "/app/public/",
                    "fallback": {
                        "pass": "applications/laravel"
                    }
                }
            }
        ]
    },

    "applications": {
        "laravel": {
            "type": "php",
            "root": "/app/public/",
            "script": "index.php"
        }
    }
}

Create symlink with ln -s /usr/lib/libphp.so /usr/lib/libphp7.so does not work (which is logical) - I get an error

 [alert] 11#11 dlopen("/usr/lib/unit/modules/php.unit.so"), failed: "/usr/lib/unit/modules/php.unit.so: undefined symbol: zend_disable_function"
mar0x commented 3 years ago

Hello, Packaged unit-php built for php version which is shipped with focal. You've installed php from 3rd party repository and you need to build your own unit-php from sources (see http://unit.nginx.org/installation/#installation-modules-php).

porozhnyy commented 3 years ago

@mar0x Thank you! Are there any plans to divide the unit-php into php versions? For example unit-php7.4, unit-php8.0, etc. This would make installation and use much easier

mar0x commented 3 years ago

Yes, we can provide different versions, if the distributive provides corresponding php packages. We cannot rely on 3rd party repositories.

thresheek commented 3 years ago

Hi @porozhnyy, please check a new Docker image we now have: nginx/unit:1.22.0-php8.0 (http://unit.nginx.org/installation/#docker-images) - hope it will suit your needs.