• wsl version: 2
  • windows version: 11
  • subSystem: ubuntu20.04
  • php version: 8.1
  • python version: 3.8.1

wsl 1 使用 depot_tools 安装  v8 会产生  permission denied  报错,如果php版本是 7.x ,可以选择安装  libv8-dev 加 pecl 安装 v8js的方式;php8.x 不支持(libv8-dev版本过低)

习惯 wsl 1 用户 的可以先升级到 wsl 2 ,安装完后再退回到 wsl 1

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

cd /tmp

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

export PATH=`pwd`/depot_tools:"$PATH"

fetch v8
# 如果这里产生了更新 depot_tools 时报错,请关闭自动更新 export DEPOT_TOOLS_UPDATE=0 && rm -rf /tmp/depot_tools/.git/

cd v8

git checkout 9.9.28

gclient sync

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

ninja -C out.gn/x64.release/

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/

cd /tmp

git clone https://github.com/phpv8/v8js.git

cd v8js

phpize

./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" CPPFLAGS="-DV8_COMPRESS_POINTERS"

make && make test

make install

# 修改 php.ini
extension=v8js.so