【发布时间】:2020-07-04 10:39:23
【问题描述】:
我尝试用这个 Dockerfile 安装 V8JS
FROM php:7.3-cli-buster
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js
RUN apt-get install -y libv8-dev
RUN pecl install v8js
RUN docker-php-ext-enable v8js
但我遇到了配置错误:
正在检查默认路径中的 V8 文件...未找到
配置:错误:请重新安装 v8 发行版错误: `/tmp/pear/temp/v8js/configure --with-php-config=/usr/local/bin/php-config --with-v8js' 失败 命令'/bin/sh -c pecl install v8js' 返回非零代码:1
完整的 cli 输出:
Sending build context to Docker daemon 35.6MB
Step 1/5 : FROM php:7.3-cli-buster
---> c7ff0bf4f6fb
Step 2/5 : RUN apt-get update -y --fix-missing && apt-get upgrade -y;
---> Using cache
---> e151d6e061d2
Step 3/5 : RUN apt-get install -y libv8-dev
---> Using cache
---> fe35f48dd8cf
Step 4/5 : RUN pecl install v8js
---> Running in d9f4ba184d81
downloading v8js-2.1.1.tgz ...
Starting to download v8js-2.1.1.tgz (101,888 bytes)
.......................done: 101,888 bytes
28 source files, building
running: phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
Please provide the installation prefix of libv8 [autodetect] : building in /tmp/pear/temp/pear-build-defaultuserEVh9Nq/v8js-2.1.1
running: /tmp/pear/temp/v8js/configure --with-php-config=/usr/local/bin/php-config --with-v8js
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 1.1.1 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for V8 Javascript Engine... yes, shared
checking for V8 files in default path... not found
configure: error: Please reinstall the v8 distribution
ERROR: `/tmp/pear/temp/v8js/configure --with-php-config=/usr/local/bin/php-config --with-v8js' failed
The command '/bin/sh -c pecl install v8js' returned a non-zero code: 1
如何解决配置错误(我猜是因为缺少 V8 文件的路径)并在 PHP Docker FROM Debian Buster 上安装 V8JS?
编辑
来自@saulotoledo 答案的Dockerfile 有效:)
构建映像大约需要 60-90 分钟,映像大小为 5.47GB,而基础映像 (FROM) 7.3-cli-buster 367MB
要使用 V8JS 构建 Dockerfile php,请从 @saulotoledo 答案中复制代码并将其粘贴到名为 Dockerfile 的文件中
然后在同一目录下运行这个命令:
docker build --tag "test-php-js" .
然后以这种方式运行容器:
docker run -it --rm --entrypoint="" --name="php-v8js" test-php-js /bin/sh
你应该登录到 php-cli 的终端,输入:
php -m
您应该会看到已启用的扩展程序列表,包括 v8js
类型:
php --ri v8js
查看一些细节,例如:
V8 Javascript Engine => enabled
V8 Engine Compiled Version => 7.4.288.21
V8 Engine Linked Version => 7.4.288.21
Version => 2.1.1
现在是你们一直在等待的樱桃部分 - 输入:
php -r "(new V8Js())->executeString(\"print('Hello' + ' from JS ' + 'World!')\", 'basic.js');";
查看支持 V8JS 的 php 运行 js 代码:D
Hello from JS World!
请注意,对于 php -r 命令,我需要在每个 JS 双引号 " 前面加上额外的反斜杠 \。但这只是由于在 cli 模式下从 php 运行 JS 作为 oneliner。
通常你不需要那个 See an official PHP documentation example
有谁知道是否可以安装和启用 V8JS 扩展而不从其源代码构建它,而是像我一开始尝试的那样使用 Debian Buster 包和 PECL?
【问题讨论】:
-
您是否已经看到github.com/phpv8/v8js/issues/206 导致此处的文档:github.com/phpv8/v8js/blob/php7/README.Linux.md?这对你有帮助吗?
-
@ChristophKluge 我尝试了提供的示例代码here,但我收到关于
fetch v8行的错误“找不到命令”。我之前添加了RUN apt-get install -y fetch,但存储库中没有这样的包。我不知道fetch是什么。你知道那个 fetch 是什么,我从哪里得到它? -
fetch是depot_tools.gitrepo 的一部分,它被加载到你的PATH中。您是否运行git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git后跟export PATH=$(pwd)/depot_tools:"$PATH"?这应该导出fetch和gclient。见这里:chromium.googlesource.com/chromium/tools/depot_tools.git#tools -
我正在为您准备一个示例 Dockerfile。它仍在编译。我现在必须离开,但我一回来会给你一个工作副本/粘贴示例的答案。
-
@ChristophKluge 谢谢,我会跟踪该票的回复。我还发现 another phpv8/v8js/issue 似乎已解决,但尚未检查是否有帮助。
标签: php docker configuration debian v8js