I tried to install V8JS with this Dockerfile
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
but I got a configuration error:
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
full cli output:
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
How to resolve configuration error (due to lack of a path to the V8 files I guess) and install V8JS on PHP Docker FROM Debian Buster?
EDIT
Dockerfile from @saulotoledo answer works 🙂
Building image takes approx 60-90 min and the image size is 5.47GB vs base image (FROM) 7.3-cli-buster 367MB
to build Dockerfile php with V8JS copy the code from @saulotoledo answer and paste it into the file named Dockerfile
Then run in the same directory this command:
docker build --tag "test-php-js" .
Then run container this way:
docker run -it --rm --entrypoint="" --name="php-v8js" test-php-js /bin/sh
you should be logged into terminal of php-cli, type:
php -m
and you should see a list of enabled extensions including v8js
type:
php --ri v8js
to see some details, something like:
V8 Javascript Engine => enabled
V8 Engine Compiled Version => 7.4.288.21
V8 Engine Linked Version => 7.4.288.21
Version => 2.1.1
and now the cherry part you all have been waiting for – type:
php -r "(new V8Js())->executeString("print('Hello' + ' from JS ' + 'World!')", 'basic.js');";
to see php running js code with V8JS support 😀
Hello from JS World!
Note that I needed to put extra backslash in front of every JS doublequote
"
for the php -r
command. But that’s only due to running JS from php in cli mode as oneliner.
Normally you don’t need that
See an official PHP documentation example
Does anyone know if it is possible to install and enable V8JS extension without building it from its source but by using Debian Buster package and PECL as I tried at the beginning?
3
Answers
Thanks to saulotoledo I created example image that takes 950MB vs 398MB base image (php:7.3-cli-buster)
It works also with PHP FPM, just change
FROM php:7.3-cli-buster
toFROM php:7.3-fpm-buster
if you want FPM version.Dockerfile
Edit:
That should solve your issue (note that I am compiling it manually):
Old answer:
I believe you need to compile the V8 manually. I am not sure yet why the
libv8-dev
is not enough. Since that does not work, you need to compile it because it is a requirement.That said, this link may be helpful. But the official compilation instructions are presented here. After a few tests I noticed you need to add
libtinfo5
(and maybelibtinfo-dev
, to be safe, but you may try it without it) to yourapt-get install
, otherwise the ninja build in the instructions will fail.After using that compilation instructions in your Dockerfile, the V8 will compile properly. After that you will still have some trouble with the pecl installation. Unfortunately I had to stop investigating the problem for now, the compilation takes some time. However, the following links may help you to solve your problem:
I hope it helps. If you manage to have a working Dockerfile please share with us later. If I have some time later to investigate it and I have some progress I will edit my answer.
This works without compiling v8 – it is very fast. Using distro packaged nodejs library. You can use current official php docker image