奇技指南
PHP 8.0 Alpha 1 已經在2020年6月25號發布了,今天跟大家分享一篇最簡化的PHP 8原始碼編譯安裝方法,快速嚐鮮PHP 8.0 的新特性JIT。
作業系統:CentOS Linux release 7.4.1708 (Core)
GCC:4.8.5 20150623 (Red Hat 4.8.5-28 )
PHP 版本:php-8.0.0alpha1
##1、下載頁面
https://downloads.php.net/~pollita/
2、下載PHP 8.0
wget https://downloads.php.net/~pollita/php-8.0.0alpha1.tar.gz
3、解壓縮
tar -zxvf php-8.0.0alpha1.tar.gz
4、新安裝目錄
#由於本機有多個PHP 版本並存,需要新建一個富有意義的目錄,一個不假思索就能知曉PHP 版本的目錄名稱。mkdir -p /usr/local/php80
5、configure options
這是精簡版設定選項,更豐富的PHP 設定選項說明:https://www.php.net/manual /en/configure.about.phpcd php-8.0.0alpha1 ./configure --prefix=/usr/local/php80/ --enable-debug --enable-fpm --with-config-file-path=/usr/local/php80/etc/ --with-config-file-scandir=/usr/local/php80/etc/php.d/
configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met: No package 'libxml-2.0' found
yum install libxml2-devel.x86_64
configure: error: Package requirements (sqlite3 > 3.7.4) were not met: No package 'sqlite3' found
yum install sqlite-devel.x86_64
6、編譯&安裝
make
Build complete. Don't forget to run 'make test'.
make install exit 0; -v -d /home/fanjiapeng/php-8.0.0alpha1/Zend/zend_ini_parser.y -o /home/fanjiapeng/php-8.0.0alpha1/Zend/zend_ini_parser.c Installing shared extensions: /usr/local/php80/lib/php/extensions/debugnon-zts-20190128/ Installing PHP CLI binary: /usr/local/php80/bin/ Installing PHP CLI man page: /usr/local/php80/php/man/man1/ Installing PHP FPM binary: /usr/local/php80/sbin/ Installing PHP FPM defconfig: /usr/local/php80/etc/ Installing PHP FPM man page: /usr/local/php80/php/man/man8/ Installing PHP FPM status page: /usr/local/php80/php/php/fpm/ Installing phpdbg binary: /usr/local/php80/bin/ Installing phpdbg man page: /usr/local/php80/php/man/man1/ Installing PHP CGI binary: /usr/local/php80/bin/ Installing PHP CGI man page: /usr/local/php80/php/man/man1/ Installing build environment: /usr/local/php80/lib/php/build/ Installing header files: /usr/local/php80/include/php/ Installing helper programs: /usr/local/php80/bin/ program: phpize program: php-config Installing man pages: /usr/local/php80/php/man/man1/ page: phpize.1 page: php-config.1 /home/fanjiapeng/php-8.0.0alpha1/build/shtool install -c ext/phar/phar.phar /usr/local/php80/bin/phar.phar ln -s -f phar.phar /usr/local/php80/bin/phar Installing PDO headers: /usr/local/php80/include/php/ext/pdo/
7、驗證PHP
/usr/local/php80/bin/php -v PHP 8.0.0alpha1 (cli) (built: Jul 2 2020 15:47:26) ( NTS DEBUG ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
#8、環境設定
ln -s /usr/local/php80/bin/php /usr/bin/php80 cp php.ini-development /usr/local/php80/etc/php.ini cp /usr/local/php80/etc/php-fpm.conf.default /usr/local/php80/etc/phpfpm.conf cp /usr/local/php80/etc/php-fpm.d/www.conf.default /usr/local/php80/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php80-fp chmod +x /etc/init.d/php80-fpm
9、驗證設定路徑
驗證自訂的組態項目是否生效:--with-config-file-path,--with-config-file-scan-dirphp80 --ini Configuration File (php.ini) Path: /usr/local/php80/etc/ Loaded Configuration File: /usr/local/php80/etc/php.ini Scan for additional .ini files in: /usr/local/php80/etc/php.d/ Additional .ini files parsed: (none)
10、啟動FPM
/etc/init.d/php80-fpm start Starting php-fpm done
11、驗證FPM
ps aux | grep php-fpm root 26876 0.0 0.0 52084 2828 ? Ss Jul02 0:14 php-fpm: master process (/usr/local/php80/etc/php-fpm.conf) nobody 26877 0.0 0.0 52084 3648 ? S Jul02 0:00 php-fpm: pool www nobody 26878 0.0 0.0 52084 3624 ? S Jul02 0:00 php-fpm: pool www /etc/init.d/php80-fpm -h Usage: /etc/init.d/php80-fpm {start|stop|forcequit|restart|reload|status|configtest} /etc/init.d/php80-fpm status php-fpm (pid 26876) is running... /etc/init.d/php80-fpm configtest [06-Jul-2020 11:06:42] NOTICE: configuration file /usr/local/php80/etc/php fpm.conf test is successful
// index.php <?php var_dump(PHP_VERSION); var_dump(PHP_VERSION_ID);
curl localhost string(11) "8.0.0alpha1" int(80000)
12、嚐鮮新特性JIT
機設定:8核心16G,SATA盤,作業系統:CentOS Linux release 7.4.1708 (Core)Zend OPCache(/usr/local/php80/etc/php.ini)設定如下,[opcache] 大部分配置項目都有預設值,為了突顯這些設定項的重要性還是列舉了出來:
; 加载 Zend OPCache 扩展 zend_extension=opcache ; 启用 Zend OPCache opcache.enable=1 ; 启用 Zend OPCache,在 CLI 模式下 opcache.enable_cli=1 ; OPCache 共享内存存储大小,默认值 128 opcache.memory_consumption=128 ; interned string 内存大小,默认值 8 opcache.interned_strings_buffer=8 ; 缓存脚本文件数量的上限,默认值 10000 opcache.max_accelerated_files=10000 ; 10秒检查一次文件的更新,默认值 2s opcache.revalidate_freq=10 ; 删除所有 PHPDoc 注释,默认值 1,表示保留注释 opcache.save_comments=0
13、總結
這是一個通用性PHP 原始碼編譯安裝方法,其它PHP 版本編譯安裝方式類似,實際業務運用中configure options 要豐富的多,需要安裝的類別庫也會更加全面。這篇文章中,測試 了 PHP 8 的新特性 JIT,依據 Zend/bench.php 測試結果看,還是讓大家眼前一亮的。關 於 PHP 8 JIT 介紹,推薦《PHP8新特性JIT使用簡介》。
推薦文章:《PHP8.0》
#
以上是PHP 8.0 原始碼編譯安裝以及 JIT 嚐鮮的詳細內容。更多資訊請關注PHP中文網其他相關文章!