Skip to content

Installing on CentOS 7 x64 PHP 7.3

Reforced edited this page Jul 11, 2019 · 6 revisions

Compiling and installing the module might cause some headache if you run into errors. The installation below was tested on an CentOS Linux release 7.6.1810 (Core) 64-bits machine and the module installed in PHP 7.3 from Plesk and Remi. Let's get started.

Installing dependencies

# V8
sudo yum --enablerepo=epel install curl git python python-software-properties glib2-devel subversion gcc gcc-c++ make chrpath redhat-lsb-core
# PHP
sudo yum php php-devel re2c

If you want your system PHP (defaults to PHP5) to be PHP 7.3 (or any other version), you need to add a repository that has provides it. I've tested here by using Remi's RPM PHP 7.3.

Recommended: Building a recent c++ compiler

You can check your current version with gcc -v. Old versions may not support the complete c++11 standard. When you run into GLIBCXX errors, incompatible libstdc++ versions, or Could not find libv8_libplatform library, this might be your answer. Note that compiling takes about an hour. A faster alternative might be using the pre-compiled devtoolset-7, but I've not tested this.

sudo yum install bzip2
cd /usr/local/src
wget https://www.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz
tar zxf gcc-8.3.0.tar.gz
cd gcc-8.3.0/
./contrib/download_prerequisites
./configure --disable-multilib --enable-languages=c,c++
make
sudo make install

If you run gcc -v now it should tell 8.3.0. If not try sudo ldconfig to refresh the shared libraries, exec bash to restart your bash session, or just a sudo reboot for your server. Additional help can be found on the internet (here for example).

Installing v8

This will build the latest stable version as of this moment used by Chromium and Chrome (7.5.288.23). You can find the currently latest stable versions here, found in the column v8_version.

# Add depot_tools
cd /usr/local
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"

# Build our v8 version
cd /usr/local/src
fetch v8
cd v8
git checkout 7.5.288.23 # v8_version here
gclient sync
./build/install-build-deps.sh
gn gen out.gn/library --args='use_custom_libcxx=false is_component_build=true is_debug=false target_cpu="x64" use_goma=false goma_dir="None" v8_enable_backtrace=true v8_enable_disassembler=true v8_enable_object_print=true v8_enable_verify_heap=true'
ninja -C out.gn/library libv8.so

# Move files we need to /opt/v8
sudo mkdir -p /opt/v8/{lib,include}
sudo cp -v out.gn/library/lib*.so out.gn/library/*_blob.bin out.gn/library/icudtl.dat /opt/v8/lib/
sudo cp -vR include/* /opt/v8/include/

# Update shared libraries when needed
sudo ldconfig

We're using gn gen for the configuration. Please refer to build documentation for more information about it or information about the available options.

Installing php-v8js

Now that v8 is installed, we can compile the module for PHP version(s). For the system PHP the workflow is as follows:

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

If your system has multiple PHP versions installed, the flow is a bit different. The example below applies to Plesk using PHP 7.3. Note the path /opt/plesk/php/7.3/bin/ as well as --with-php-config option. Repeat for any version you want to compile the module for.

# No need to repeat if done once
# cd /usr/local/src
# git clone https://github.com/phpv8/v8js.git
# cd v8js

/opt/plesk/php/7.3/bin/phpize
./configure --with-v8js=/opt/v8 --with-php-config=/opt/plesk/php/7.3/bin/php-config LDFLAGS="-lstdc++"
make -B
make test
sudo make install

After sudo make install the location of the v8js.so module will be shown, for example /opt/plesk/php/7.3/lib64/php/modules/.

Enable the module in your php.ini

Add extension=v8js.so to your php.ini file. You can check the location of you php.ini file via php --ini. You can also specify the full path, given in the last step. E.g. extension=/opt/plesk/php/7.3/lib64/php/modules/v8js.so.

Restart your webserver when needed and you should be good to go!

You can run echo "<?php phpinfo();" | php | grep -i v8 to test.

Result

Clone this wiki locally