Last active
December 9, 2020 20:14
-
-
Save lucenarenato/eab40ae96bd3e0fc40abfd697f383f33 to your computer and use it in GitHub Desktop.
Instalando v8js no Ubuntu 18.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Instalando v8js no Ubuntu 18.04 | |
Processo de compilação V8js para Ubuntu 18.04 | |
Versão compilada | |
Baixe o arquivo e descompacte-o em / opt / google. O arquivo contém a biblioteca v8 e a extensão v8js.so para php7.2. | |
mkdir -p /opt/google | |
cd /opt/google | |
wget https://blog.bayrell.org/media/files/archives/v8-ubuntu-18.04-x64-6.4.388.18-2.1.0.tar.gz | |
Verifique o arquivo baixado: | |
md5sum -b v8-ubuntu-18.04-x64-6.4.388.18-2.1.0.tar.gz | |
Deveria estar: | |
5019edf488ace4c3a46449bf7cbb6e7b *v8-ubuntu-18.04-x64-6.4.388.18-2.1.0.tar.gz | |
## Descompacte o arquivo | |
tar xvf v8-ubuntu-18.04-x64-6.4.388.18-2.1.0.tar.gz | |
A pasta conterá v8js.so deve ser copiada para / usr / lib / php / 20170718 e registrada na configuração php: | |
cp /opt/google/v8/6.4/v8js.so /usr/lib/php/20170718 | |
Por exemplo nano /etc/php/7.2/cli/conf.d/50-v8js.ini | |
extension=v8js.so | |
php --ri v8js | |
*********************************************************************************************************************** | |
## Processo de compilação | |
Compile apenas em um contêiner LXC separado e seguro. | |
O contêiner é necessário para não quebrar o sistema host. Melhor coletado em um recipiente. E copie o resultado final para o sistema host. | |
Instale o LXC . | |
Crie um contêiner se ele ainda não tiver sido criado: | |
lxc-create -t download -n test-ubuntu -- --dist ubuntu --release bionic --arch amd64 | |
Inicie o contêiner: | |
lxc-start test-ubuntu | |
Conecte ao contêiner: | |
lxc-attach test-ubuntu | |
Instalando libv8 em um contêiner: | |
apt update | |
apt install build-essential python python3 chrpath re2c git curl wget gcc-7 gcc-7-base libgcc-7-dev libglib2.0-dev -y | |
echo "mcgrathr:x:0:0:root:/root:/bin/bash" >> /etc/passwd | |
echo "thomasanderson:x:0:0:root:/root:/bin/bash" >> /etc/passwd | |
echo "eng:x:0:" >> /etc/group | |
echo "primarygroup:x:0:" >> /etc/group | |
# Установить depot_tools | |
mkdir -p /opt/google/src | |
cd /opt/google/src | |
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git | |
# Включить инструменты depot_tools fetch and gclient | |
export PATH=/opt/google/src/depot_tools:"$PATH" | |
# Скачать v8 | |
cd /opt/google/src | |
fetch v8 | |
cd v8 | |
# Остальные версии | |
# git checkout 5.6.326.12 | |
# git checkout 6.4.388.18 | |
# git checkout 7.5.288.23 | |
# git checkout 7.9.335 | |
# git checkout 8.4.49 | |
# Рабочая версия | |
git checkout 6.4.388.18 | |
gclient sync | |
# Компиляция | |
tools/dev/v8gen.py -vv x64.release -- is_component_build=true | |
ninja -C out.gn/x64.release libv8.so | |
# Прочие команды, которые не работают | |
# ./build/install-build-deps.sh | |
# tools/dev/gm.py x64.release | |
# ninja -C out/x64.release | |
# gn gen out.v8/x64 --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' | |
Copie os arquivos para / opt / google / src / v8: | |
cd /opt/google/src/v8 | |
mkdir -p /opt/google/v8/6.4/{lib,include} | |
cp -v out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/google/v8/6.4/lib/ | |
cp -vR include/* /opt/google/v8/6.4/include/ | |
Bibliotecas de patches. Este comando corrige os caminhos de pesquisa da biblioteca. | |
cd /opt/google/v8 | |
apt-get install patchelf | |
for A in /opt/google/v8/6.4/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done | |
Compilando v8js | |
cd /opt/google/src | |
apt install php7.2-dev -y | |
git clone https://github.com/phpv8/v8js.git | |
cd v8js | |
# Версия для v8 6.4.388.18 | |
git checkout 2.1.0 | |
# Конфигурация | |
phpize | |
./configure --with-v8js=/opt/google/v8/6.4 LDFLAGS="-lstdc++" | |
# Компиляция и тестирование | |
make && make test | |
# Установка версии | |
make install | |
Em seguida, você precisa se registrar na configuração do php nano /etc/php/7.2/cli/conf.d/50-v8js.ini | |
extension=v8js.so | |
Instalando v8js via pecl | |
Este método não é recomendado. Compilar via git como acima | |
Corre: | |
pecl install v8js-2.1.0 | |
Quando perguntado onde a libv8 está localizada: | |
Please provide the installation prefix of libv8 [autodetect] : | |
aponte para a pasta /opt/google/v8/6.4 | |
Testando | |
Crie o arquivo test.php | |
<?php | |
$v8 = new V8Js(); | |
$JS = <<< EOT | |
var s = 'Hello world'; | |
s; | |
EOT; | |
$r = $v8->executeString($JS); | |
var_dump($r); | |
Execute este arquivo: | |
php test.php | |
Deve produzir: | |
string(11) "Hello world" | |
## - https://blog.bayrell.org/ru/linux/219-ustanovka-v8js-ubuntu-18-04.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment