前言
mac版v8js的安装真的是各种问题,相信大家尝试过的都深有感触,我在网上找了各种教程,大多都是千篇一律,而且大多数都是php5的老版本的,最终在
GitHub issues 找到了解决方案,因此在此记录一下。
版本
- Mac OS :10.15.4
- PHP: 7.2.30
- PECL: 1.10.11
➜ ~ sw_vers ProductName: Mac OS X ProductVersion: 10.15.4 BuildVersion: 19E287 ➜ ~ php -v PHP 7.2.30 (cli) (built: Apr 22 2020 10:13:14) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.30, Copyright (c) 1999-2018, by Zend Technologies ➜ ~ pecl version PEAR Version: 1.10.11 PHP Version: 7.2.30 Zend Engine Version: 3.2.0 Running on: Darwin localhost 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
安装V8
- 确保您的系统上以前没有安装v8。
- 下载此v8自制公式(v8 7.4.288.25) https://raw.githubusercontent.com/Homebrew/homebrew-core/0a6171330678879285f2c566db9349da421d6f62/Formula/v8.rb (需翻墙)
- 使用下载的公式安装v8:brew install v8.rb
安装v8js扩展
- 将v8js克隆到本地: git clone https://github.com/phpv8/v8js
- 从源代码构建v8js:
cd v8js phpize ./configure CXXFLAGS="-Wno-c++11-narrowing" --with-v8js="/usr/local/Cellar/v8/7.4.288.25/libexec" make make test make install
在PHP中启用v8js
- 查找php.ini文件
➜ ~ php --ini Configuration File (php.ini) Path: /usr/local/etc/php/7.2 Loaded Configuration File: /usr/local/etc/php/7.2/php.ini Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d Additional .ini files parsed: /usr/local/etc/php/7.2/conf.d/ext-opcache.ini,
- 打开php.ini文件
vim /usr/local/etc/php/7.2/php.ini
- 将此行添加到开头并保存ini文件: extension =”v8js.so”
- 重新启动PHP
brew services restart php