我试图用这个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/配置-with config=/usr/local/bin/php-config-with- v8js‘失败-命令'/bin/sh -c tmp 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文件的路径)并从Debian在PHP上安装V8JS?
编辑
@saulotoledo应答工作文档:)
建筑物图像大约需要60-90分钟,图像大小为5.47GB与基本图像(从7.3-cli-buster 367 vs )相比
要用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');";
若要看到php运行带有V8JS支持的js代码:D
Hello from JS World!
注意,我需要在\
命令的每个JS双引号"
前面加上额外的反斜杠php -r
。但这只是因为在cli模式下以oneliner的身份从php运行JS。
通常你不需要那个请参阅正式的PHP文档示例
有人知道是否可以安装和启用V8JS扩展,而不需要从源代码构建它,而是使用Debian包和PECL,就像我在一开始尝试的那样?
发布于 2022-07-21 10:34:07
这不需要编译v8 --它非常快。使用发行版打包的nodejs库。您可以使用当前的正式php停靠映像。
RUN apt-get install -y libnode-dev \
&& cp -s /usr/lib/x86_64-linux-gnu/libv8* /usr/local/lib/ \
&& cp -rs /usr/include/node/* /usr/local/include/ \
&& pecl install v8js \
&& echo "extension=v8js.so" > /usr/local/etc/php/conf.d/v8js.so
https://stackoverflow.com/questions/60822501
复制相似问题