php - 'Opcache'无法在Docker中安装

标签 php apache docker debian opcache

我已经用图像“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输出:
----------------------------------------------------------------------
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

快乐的编码:)

关于php - 'Opcache'无法在Docker中安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58820032/

相关文章:

java - 包 org.apache.commons 不存在

visual-studio - Docker AspNet Core + Couchbase

apache - 使用 .htaccess 将一个文件夹重定向到另一个文件夹,但保留原始 URL 并阻止对所有其他文件夹的访问

wordpress - 使用 .htaccess 将 WordPress 上传文件夹重定向到 s3 存储桶

javascript - 将背景应用到动态生成的表中的第一行和每第三行

php - wordpress导航栏如何添加跳转链接?

由于 "<urlopen error unknown url type: https>",Python HTTPS 下载失败

docker - 公开在gitlab ci docker镜像中运行的服务器

php - 在 CakePHP 中,覆盖 AppController 的 redirect() 以在 ajax 请求期间通过 json 响应 url

PHP strtotime 和 MySQL 日期格式