phpv8/v8js

This LIB is very hard to install !

tbarillet opened this issue · 14 comments

Why is this lib so difficult to install? Why do we have to do dozens of manipulations/builds just to install this extension? Why libv8-dev and pecl install v8js are not enough!

It's crazy, there are almost no resources on the internet to install this library on recent versions of PHP (like 8.1 or 8.2) or on recent operating systems (Ubuntu 22+, CentOS) what a hassle !

After dozens of attempts, I still haven't succeeded, hell you have to have a doctorate in software engineering to install this lib! What hell ?

Can you do something and give clear and complete instructions on how to install this lib on php 8.2 and Ubuntu 22.04 for example?

Followed :

https://github.com/phpv8/v8js/blob/php8/README.Linux.md

Error :

ninja -C out.gn/x64.release/
ninja: Entering directory `out.gn/x64.release/'
[1/1] Regenerating ninja files
[85/2025] ACTION //src/inspector:protocol_generated_sources(//build/toolchain/linux:clang_x64)
FAILED: gen/src/inspector/protocol/Forward.h gen/src/inspector/protocol/Protocol.cpp gen/src/inspector/protocol/Protocol.h gen/src/inspector/protocol/Console.cpp gen/src/inspector/protocol/Console.h gen/src/inspector/protocol/Debugger.cpp gen/src/inspector/protocol/Debugger.h gen/src/inspector/protocol/HeapProfiler.cpp gen/src/inspector/protocol/HeapProfiler.h gen/src/inspector/protocol/Profiler.cpp gen/src/inspector/protocol/Profiler.h gen/src/inspector/protocol/Runtime.cpp gen/src/inspector/protocol/Runtime.h gen/src/inspector/protocol/Schema.cpp gen/src/inspector/protocol/Schema.h gen/include/inspector/Debugger.h gen/include/inspector/Runtime.h gen/include/inspector/Schema.h
python ../../third_party/inspector_protocol/code_generator.py --jinja_dir ../../third_party/ --output_base gen/src/inspector --config ../../src/inspector/inspector_protocol_config.json --inspector_protocol_dir ///third_party/inspector_protocol
Traceback (most recent call last):
  File "/tmp/v8/out.gn/x64.release/../../third_party/inspector_protocol/code_generator.py", line 725, in <module>
    main()
  File "/tmp/v8/out.gn/x64.release/../../third_party/inspector_protocol/code_generator.py", line 601, in main
    jinja_env = initialize_jinja_env(jinja_dir, config.protocol.output, config)
  File "/tmp/v8/out.gn/x64.release/../../third_party/inspector_protocol/code_generator.py", line 190, in initialize_jinja_env
    import jinja2
  File "/tmp/v8/third_party/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/tmp/v8/third_party/jinja2/environment.py", line 16, in <module>
    from jinja2.defaults import BLOCK_START_STRING, \
  File "/tmp/v8/third_party/jinja2/defaults.py", line 32, in <module>
    from jinja2.tests import TESTS as DEFAULT_TESTS
  File "/tmp/v8/third_party/jinja2/tests.py", line 13, in <module>
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[86/2025] SOLINK ./libv8_libbase.so
FAILED: libv8_libbase.so libv8_libbase.so.TOC
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm" --sofile="./libv8_libbase.so" --tocfile="./libv8_libbase.so.TOC" --output="./libv8_libbase.so" -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,-soname="libv8_libbase.so" -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,defs -Wl,--as-needed -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -m64 -Werror -rdynamic --sysroot=../../build/linux/debian_sid_amd64-sysroot -L../../build/linux/debian_sid_amd64-sysroot/usr/local/lib/x86_64-linux-gnu -L../../build/linux/debian_sid_amd64-sysroot/lib/x86_64-linux-gnu -L../../build/linux/debian_sid_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath=\$ORIGIN -Wl,-O2 -Wl,--gc-sections -o "./libv8_libbase.so" @"./libv8_libbase.so.rsp"
Traceback (most recent call last):
  File "/tmp/v8/out.gn/x64.release/../../build/toolchain/gcc_solink_wrapper.py", line 151, in <module>
    sys.exit(main())
  File "/tmp/v8/out.gn/x64.release/../../build/toolchain/gcc_solink_wrapper.py", line 134, in main
    result, toc = CollectTOC(args)
  File "/tmp/v8/out.gn/x64.release/../../build/toolchain/gcc_solink_wrapper.py", line 44, in CollectTOC
    result, toc = CollectSONAME(args)
  File "/tmp/v8/out.gn/x64.release/../../build/toolchain/gcc_solink_wrapper.py", line 27, in CollectSONAME
    if 'SONAME' in line:
TypeError: a bytes-like object is required, not 'str'
[87/2025] CXX obj/third_party/googletest/gtest/gtest-filepath.o
ninja: build stopped: subcommand failed.

Hi, you are right, installing of v8js on modern versions of PHP is confusing because the documentation is not up to date.

On the other hand, the latest version available in PECL specifies that it does not support php8:

https://pecl.php.net/package-changelog.php?package=v8js&release=2.1.2


I was able to install v8js on php 8.2.9 after a few minutes examining the config.m4 file and my old v8js installation on php 7.2.

Here is an installation guide for debian bookworm and php 8.2.9.

v8 library installation:

apt install libnode-dev

After installation it is necessary to copy the files with the structure needed by v8js for compilation:

mkdir /opt/v8
mkdir /opt/v8/lib
mkdir /opt/v8/includes

copy v8 files from /usr/lib/x86_64-linux-gnu/, to /opt/v8js/lib.

ls /opt/v8/lib
libnode.so libnode.so.108 libv8.so libv8_libbase.so libv8_libplatform.so libv8_libsampler.so

copy v8 includes from /usr/include/v8 to /opt/v8/include

cp -r /usr/include/v8/* /opt/v8/include/

Installing v8js

cd /opt/
git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++"
make
make test
make install

Then add extension=v8js.so to your php.ini file

Hi, you are right, installing of v8js on modern versions of PHP is confusing because the documentation is not up to date.

On the other hand, the latest version available in PECL specifies that it does not support php8:

https://pecl.php.net/package-changelog.php?package=v8js&release=2.1.2

I was able to install v8js on php 8.2.9 after a few minutes examining the config.m4 file and my old v8js installation on php 7.2.

Here is an installation guide for debian bookworm and php 8.2.9.

v8 library installation:

apt install libnode-dev

After installation it is necessary to copy the files with the structure needed by v8js for compilation:

mkdir /opt/v8
mkdir /opt/v8/lib
mkdir /opt/v8/includes

copy v8 files from /usr/lib/x86_64-linux-gnu/, to /opt/v8js/lib.

ls /opt/v8/lib
libnode.so libnode.so.108 libv8.so libv8_libbase.so libv8_libplatform.so libv8_libsampler.so

copy v8 includes from /usr/include/v8 to /opt/v8/include

cp -r /usr/include/v8/* /opt/v8/include/

Installing v8js

cd /opt/
git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++"
make
make test
make install

Then add extension=v8js.so to your php.ini file

thanks, it's work for me with php8.0

Thank you very much ! before posting this message, i was frustrated because i have spent a lot of time trying to install this library.

I finally succeeded few hours after this message, in another way that your way. But your way is easier and better.

I encountered many compilation errors, one was because the prototype of a function mismatch between the v8 lib and this lib.

So i take my courage at two hands and decided to edit the C code by myself to fix the prototype. And after recompiling, it worked.

But thanks for considering my message and to give to everyone a working and easy solution. I'm sure that it will help a lot of people.

@jcastilloa do you know how to do with CentOS 7?

@jcastilloa do you know how to do with CentOS 7?

@art-fatal, I think so, try installing the packages nodejs-libs and nodejs-devel to provide the v8 library and the includes

@tbarillet did you manage to install it on CentOS?

kasd commented

@art-fatal I managed to install it on CentOS 7 + remi, dm me if you need help.