Skip to content

Instantly share code, notes, and snippets.

@aozisik
Last active June 14, 2023 12:28
Show Gist options
  • Save aozisik/a522e3b602daff6ae51f134aa949eec9 to your computer and use it in GitHub Desktop.
Save aozisik/a522e3b602daff6ae51f134aa949eec9 to your computer and use it in GitHub Desktop.
Installing PHP v8js on Ubuntu 18.04 Bionic or Mac OS Mojave (brew)
# This will retrieve v8 7.4.288.25 when installled
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/0a6171330678879285f2c566db9349da421d6f62/Formula/v8.rb
brew install v8.rb
brew list v8
# You will see this:
# /usr/local/Cellar/v8/7.4.288.25/bin/d8
# /usr/local/Cellar/v8/7.4.288.25/libexec/include/ (21 files)
# /usr/local/Cellar/v8/7.4.288.25/libexec/ (7 files)
mkdir -p /usr/local/Cellar/v8/7.4.288.25/libexec/lib
cp /usr/local/Cellar/v8/7.4.288.25/libexec/* /usr/local/Cellar/v8/7.4.288.25/libexec/lib
# Ignore the following errors, everything is fine:
# cp: /usr/local/Cellar/v8/7.4.288.25/libexec/include is a directory (not copied).
# cp: /usr/local/Cellar/v8/7.4.288.25/libexec/lib is a directory (not copied).
cd /tmp
git clone https://github.com/phpv8/v8js
cd v8js
git checkout php7
phpize
./configure CXXFLAGS="-Wno-c++11-narrowing" --with-v8js="/usr/local/Cellar/v8/7.4.288.25/libexec"
make
make test
# Make sure that make test succeeds
make install
# Expected output:
# Installing shared extensions: /usr/local/Cellar/php@7.2/7.2.18/pecl/20170718/
# Check if it's already working:
php -m | grep v8js
# No? It's not there?
# You may need to add v8js.so to your php.ini
# Locate your php.ini by doing:
php --ini
# Open the file and add: extension="v8js.so"
# Enjoy!
# Guys/gals... This took >4 hours to get right.
#
# Here are some troubleshooting checklist in case you're getting errors:
#
# - Make sure you have no other v8 libraries lying around your system. Get rid of those first!
# - Run apt-get update and upgrade before running this. Obviously...
# - I got v8js-2.0.0 working against 6.4.388.18. Never got it to work against v8-7.x...
# - Don't even try apt-get install libv8-7.2. Lost hours, couldn't get it to work... Just compile yourself...
# Install required dependencies
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
# I needed this to make it work with PHP 7.1
git checkout 6.4.388.18
gclient sync
# Setup GN
tools/dev/v8gen.py -vv x64.release -- is_component_build=true
# Build
ninja -C out.gn/x64.release/
# Move libraries to necessary location
cp out.gn/x64.release/lib*.so /usr/lib/
cp out.gn/x64.release/*_blob.bin /usr/lib
cp out.gn/x64.release/icudtl.dat /usr/lib
cp -R include/* /usr/include
cd out.gn/x64.release/obj
ar rcsDT libv8_libplatform.a v8_libplatform/*.o
# Are you getting v8 (library) not found error? Try this before pecl install:
apt-get install patchelf
for A in /usr/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done
# Then let's pull v8js.
cd /tmp
git clone https://github.com/phpv8/v8js.git
cd v8js
# Checkout version 2.1.0
git checkout 2.1.0
phpize
# This flag is important!
./configure LDFLAGS="-lstdc++" --with-v8js=/usr
make clean
make
# Make sure that the tests pass...
make test
make install
# DON'T FORGET TO Add
# extension=v8js.so
# To your php.ini as needed.
# You can check if the module is there by doing php -m | grep v8js
@ready-fight
Copy link

@Dark-Aii Read this. It may help solve your problem and anyone elses:

Figured it out - wrong libv8 version:

checking for libv8_libplatform... found
checking for V8 version... 5.2.371
configure: WARNING: libv8 prior to 6.4.388.18 is missing speculative execution mitigations
My assumption was that leaving out the optional commands (from README.Linux.md) would build the latest v8 (7.5+ for ex.) - but that's not the case and it ends up building 5.2:

(optional) If you'd like to build a certain version:

git checkout 6.4.388.18
gclient sync
I've added the following commands and everything worked great (7.5.288.30 was latest stable via https://omahaproxy.appspot.com/ when I checked):

git checkout 7.5.288.30
gclient sync
Since v8js requires 6.9+ now maybe update the README.*.md's to direct users to install a version of v8 compatible with v8js? 6.9.427.18, 7.5.288.30 or otherwise?

Similar issue #421 from a couple days ago when trying to use the 6.4.388.18 version called out in README.Linux.md

@sss03
Copy link

sss03 commented Aug 13, 2019

@ss03 I'm familiar with this error, but don't know exactly what caused it. It's either your v8 version or you're not following the gist step by step. Make sure you get rid of all the pre-existing v8 versions and install the versions that I point out in the gist. Wish you lots of luck

Thanks a lot.
It worked.
I ran phpize command before ./configure LDFLAGS="-lstdc++" --with-v8js=/usr.
Hope it helps others.
Regards

@biey-root
Copy link

biey-root commented Mar 31, 2020

@Dark-Aii Read this. It may help solve your problem and anyone elses:

Figured it out - wrong libv8 version:

checking for libv8_libplatform... found
checking for V8 version... 5.2.371
configure: WARNING: libv8 prior to 6.4.388.18 is missing speculative execution mitigations
My assumption was that leaving out the optional commands (from README.Linux.md) would build the latest v8 (7.5+ for ex.) - but that's not the case and it ends up building 5.2:

(optional) If you'd like to build a certain version:

git checkout 6.4.388.18
gclient sync
I've added the following commands and everything worked great (7.5.288.30 was latest stable via https://omahaproxy.appspot.com/ when I checked):

git checkout 7.5.288.30
gclient sync
Since v8js requires 6.9+ now maybe update the README.*.md's to direct users to install a version of v8 compatible with v8js? 6.9.427.18, 7.5.288.30 or otherwise?

Similar issue #421 from a couple days ago when trying to use the 6.4.388.18 version called out in README.Linux.md

#For PHP 7.3
#use V8js version 2.1.1 instead of 2.1.0. and v8 version 7.5.288.30
git checkout 6.4.388.18 -> git checkout 7.5.288.30
git checkout 2.1.0 -> git checkout 2.1.1
#Tested on Ubuntu 18.04

Reference:
https://github.com/phpv8/v8js/releases/tag/2.1.1

@nadeemcrewlogix
Copy link

I'm facing issue to configuring v8js on mac and ubuntu 18

Can you help out to figure out this issue

checking how to allow c++11 narrowing... -Wno-c++11-narrowing
checking for libv8_libplatform... configure: error: could not find libv8_libplatform library

@KarimGeiger
Copy link

Just wanted to say thank you. After days of struggling with installing this shitload of a software, this is the first tutorial that finally worked. It even installed no problem on the M1 mac mini (using Rosetta2). You are my hero!

@jbrtsnts
Copy link

@KarimGeiger I'm on M1 mac mini as well stuck on

v8: Calling cellar in a bottle block is disabled! Use brew style --fix on the formula to update the style or use sha256 with a cellar: argument instead.

How do you manage to make it work? Thanks.

@KarimGeiger
Copy link

@jbrtsnts I didn't get that error message at all, so I don't know how to fix that. But I ran it using Rosetta 2, so prefixing every command with arch -x86_64 to run it on the x86 architecture, instead of ARM. Maybe that helps.

@jbrtsnts
Copy link

@KarimGeiger, I finally got it working. The formula is not working anymore, and only have to go with the latest version - 9.1.269.36 at the time of this comment. Thanks anyway for the quick response!

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