Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Last active April 2, 2020 13:39
Show Gist options
  • Save kirilkirkov/bc09c2ca5879abe3dc08491bdf1a4ba9 to your computer and use it in GitHub Desktop.
Save kirilkirkov/bc09c2ca5879abe3dc08491bdf1a4ba9 to your computer and use it in GitHub Desktop.
PHP 7.2 V8JS Installation on Ubuntu 18
# 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.
@kirilkirkov
Copy link
Author

@kirilkirkov
Copy link
Author

kirilkirkov commented Apr 2, 2020

Good plugin for Laravel and Vuejs that support v8js and node server compile- https://github.com/spatie/laravel-server-side-rendering

@kirilkirkov
Copy link
Author

Not in all situations work with this type of SSR because the global window variable used in browsers is not present in v8 and if plugins are used in them we cannot change the code to check whether localStorage can also be used and if we have a login it will be a problem.

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