Skip to content

Instantly share code, notes, and snippets.

@lucenarenato
Last active May 6, 2023 07:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucenarenato/75fcfeed9b70003e8846ac94e8d5c316 to your computer and use it in GitHub Desktop.
Save lucenarenato/75fcfeed9b70003e8846ac94e8d5c316 to your computer and use it in GitHub Desktop.
PHP 7.2 V8JS Installation on Ubuntu 20

Install required dependencies

sudo apt-get install build-essential curl git python libglib2.0-dev

cd /tmp

Install depot_tools first (needed for source checkout)

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"

Download v8

fetch v8
cd v8

If you'd like to build a certain version:

For php 7.4 support added in this commit - https://github.com/stesie/v8js/commit/ab6e2267afefa8f4e0c34c6be115acc14c5cad1d - MAYBE WILL NOT WORK! Use 7.2 instead

git checkout 7.0.276.3

For php 7.2

git checkout 6.4.388.18
gclient sync

Choose python 2.7

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
sudo update-alternatives --config python - CHOOSE PYTHON 2.7

Setup GN

MUST USE PYTHON 2.7 to execute this else you will see errors!!

tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false

Build

ninja -C out.gn/x64.release/

Install to /opt/v8/

sudo mkdir -p /opt/v8/{lib,include}
sudo cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin \
  out.gn/x64.release/icudtl.dat /opt/v8/lib/
sudo cp -R include/* /opt/v8/include/

sudo apt-get install patchelf
for A in /opt/v8/lib/*.so; do sudo patchelf --set-rpath '$ORIGIN' $A; done

Compile php-v8js itself

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

Then add extension=v8js.so to your php.ini file. If you have a separate configuration for CLI, add it there also.

V8Js' build system assumes that the icudtl.dat file is located next to the libv8.so library file and compiles the path into the library itself. If for whatever reason the icudtl.dat file is stored at a different place during runtime, you need to set the php.ini variable v8js.icudtl_dat_path to point to the file. Otherwise locale-aware features of V8 will not work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment