Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This LIB is very hard to install ! #522

Open
tbarillet opened this issue Sep 14, 2023 · 14 comments
Open

This LIB is very hard to install ! #522

tbarillet opened this issue Sep 14, 2023 · 14 comments

Comments

@tbarillet
Copy link

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?

@tbarillet
Copy link
Author

tbarillet commented Sep 14, 2023

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.

@jcastilloa
Copy link

jcastilloa commented Sep 15, 2023

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

@art-fatal
Copy link

art-fatal commented Sep 26, 2023

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

@tbarillet
Copy link
Author

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.

@art-fatal
Copy link

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

@jcastilloa
Copy link

@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

@art-fatal
Copy link

@tbarillet did you manage to install it on CentOS?

@kasd
Copy link

kasd commented Oct 18, 2023

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

@joehoyle
Copy link

FWIW this is why I created https://github.com/joehoyle/php-v8js which is a re-implementation of this lib. V8 is included directly on the pre-built php extension so there's no need to mess around with trying to install libv8 on the system

@redbullmarky
Copy link
Collaborator

@joehoyle i get that you’re trying to help but using issues as a means to divert people away from a project kinda feels a tad awkward and not really in the spirit of open source projects

@redbullmarky
Copy link
Collaborator

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

Perhaps you’d be ok to paste the details here? Then we can probably update the documentation for others :)

@Westacular
Copy link

I was able to get this building on Alpine 3.19 by installing the nodejs-dev package and linking to the libnode.so from that package, which bundles a version of v8 and contains the necessary libv8 symbols. All tests pass.

You can see the changes I made to v8js for this here — I just replaced various references to the various v8 libraries in config.m4 with the monolith node library.

It would be nice to make this something that could be merged back — i.e., update the autoconf logic such that it autodetects and links with either libv8 or libnode, depending on which is present — but I don't know autoconf well enough to really make that change (and don't have the time needed to learn it).

@dinamic
Copy link

dinamic commented Apr 5, 2024

@Westacular I guess you could open a PR with the changes

@dinamic
Copy link

dinamic commented Apr 5, 2024

Here's how my Dockerfile looks like, this example is with php 8.3 and Debian 12.
It uses libnode and symlinks the required folders.

https://gist.github.com/dinamic/60a573e6ffa8749f94931a4d7cfcfcb8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants