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
@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