繁体   English   中英

'Opcache' 无法安装在 Docker 中

[英]'Opcache' fails to install in Docker

我已经使用图像“FROM php:7.3-apache-stretch”设置了新的 Docker 容器,并尝试在其中安装“Opcache”但失败。

系统: Linux

PHP 版本: 7.3.11

Apache 版本: Apache/2.4.25 (Debian)

DockerFile

FROM php:7.3-apache-stretch

ARG DEBIAN_FRONTEND=noninteractive

# Update
RUN apt-get -y update --fix-missing && \
    apt-get upgrade -y && \
    apt-get --no-install-recommends install -y apt-utils && \
    rm -rf /var/lib/apt/lists/*


# Install useful tools and install important libaries
RUN apt-get -y update && \
    apt-get -y --no-install-recommends install nano vim wget dialog libsqlite3-dev libsqlite3-0 && \
    apt-get -y --no-install-recommends install mysql-client zlib1g-dev libzip-dev libicu-dev && \
    apt-get -y --no-install-recommends install --fix-missing apt-file apt-utils build-essential git curl && \ 
    apt-get -y --no-install-recommends install --fix-missing libcurl3 libcurl3-dev zip openssl && \
    rm -rf /var/lib/apt/lists/* && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Other PHP7 Extensions

RUN docker-php-ext-install pdo_mysql && \
    docker-php-ext-install pdo_sqlite && \
    docker-php-ext-install mysqli && \
    docker-php-ext-install curl && \
    docker-php-ext-install tokenizer && \
    docker-php-ext-install json && \
    docker-php-ext-install zip && \
    docker-php-ext-install -j$(nproc) intl && \
    docker-php-ext-install mbstring && \
    docker-php-ext-install gettext

# Install Freetype 
RUN apt-get -y update && \
    apt-get --no-install-recommends install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \
    rm -rf /var/lib/apt/lists/* && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install -j$(nproc) gd

# Enable apache modules
RUN a2enmod rewrite headers

# Cleanup
RUN rm -rf /usr/src/*

系统中可用的扩展列表:

root@24dd119aaa1f:/usr/local/lib/php/extensions/no-debug-non-zts-20180731# ls -l
total 4968
-rwxr-xr-x 1 root staff  111872 Nov 11 16:22 curl.so
-rwxr-xr-x 1 root staff  453536 Nov 11 16:24 gd.so
-rwxr-xr-x 1 root staff   18616 Nov 11 16:23 gettext.so
-rwxr-xr-x 1 root staff 1667064 Nov 11 16:22 intl.so
-rwxr-xr-x 1 root staff   50216 Nov 11 16:22 json.so
-rwxr-xr-x 1 root staff 1795120 Nov 11 16:23 mbstring.so
-rwxr-xr-x 1 root staff  170520 Nov 11 16:22 mysqli.so
-rwxr-xr-x 1 root staff  531752 Oct 25 02:54 opcache.so
-rwxr-xr-x 1 root staff   37800 Nov 11 16:21 pdo_mysql.so
-rwxr-xr-x 1 root staff   40176 Nov 11 16:21 pdo_sqlite.so
-rwxr-xr-x 1 root staff   80296 Oct 25 02:54 sodium.so
-rwxr-xr-x 1 root staff   27224 Nov 11 16:22 tokenizer.so
-rwxr-xr-x 1 root staff   78976 Nov 11 16:22 zip.so
root@24dd119aaa1f:/usr/local/etc/php/conf.d# ls -l
total 28
-rw-r--r-- 1 root staff 16 Nov 11 16:24 docker-php-ext-gd.ini
-rw-r--r-- 1 root staff 21 Nov 11 16:23 docker-php-ext-gettext.ini
-rw-r--r-- 1 root staff 18 Nov 11 16:22 docker-php-ext-intl.ini
-rw-r--r-- 1 root staff 20 Nov 11 16:22 docker-php-ext-mysqli.ini
-rw-r--r-- 1 root staff 23 Nov 11 16:21 docker-php-ext-pdo_mysql.ini
-rw-r--r-- 1 root staff 20 Oct 25 02:54 docker-php-ext-sodium.ini
-rw-r--r-- 1 root staff 17 Nov 11 16:22 docker-php-ext-zip.ini

php.ini

; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
opcache.max_accelerated_files=10000

尝试安装 Opcache 时:

root@24dd119aaa1f:/usr/local/lib/php/extensions/no-debug-non-zts-20180731# docker-php-ext-install opcache
tar (child): /usr/src/php.tar.xz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

确保安装了 xz-utils:

root@24dd119aaa1f:/usr/local/lib/php/extensions/no-debug-non-zts-20180731# apt-get install xz-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
xz-utils is already the newest version (5.2.2-1.2+b1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

不知道哪里出错了? 顺便说一句,我无法重新创建 docker 图像,因为这会妨碍现有项目。

使用这个 Dockerfile:

FROM php:7.3-apache-stretch
RUN docker-php-ext-install -j$(nproc) opcache

这边走:

docker build --tag stackoverflow .

给出cli output:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/src/php/ext/opcache/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

和命令:

docker run --rm -it --entrypoint="" stackoverflow /bin/sh

然后进入 CLI

php -m

提供信息:

[Zend Modules]
Zend OPcache

快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM