# test **Repository Path**: az13js/test ## Basic Information - **Project Name**: test - **Description**: 只是用来测试和学习gitee配置方法用的仓库。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: test_php7.4 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-19 - **Last Updated**: 2023-03-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CentOS7编译安装PHP7.4 CentOS7采用最小化安装,配置为2核2GB,其中内存部分不能小于或等于1GB。目的是把 需要的扩展和功能编译进去,编译步骤仅供参考。 一,安装编译过程中需要的包。 # yum install -y gcc gcc-c++ libxml2 libxml2-devel sqlite-devel sqlite \ libwebp libwebp-devel libwebp-tools libffi libffi-devel libtiff \ libtiff-devel libtiff-tools libpng libpng-devel libpng12 libpng12-devel \ openssl-devel openssl freetype freetype-devel libXpm libXpm-devel libicu \ libicu-devel bzip2-devel bzip2 libcurl-devel libcurl enchant-devel \ enchant gmp-devel gmp openldap openldap-devel cyrus-sasl-ldap \ openldap-clients compat-openldap aspell-devel enchant-aspell aspell \ readline-devel readline net-snmp net-snmp-devel libxslt-devel libxslt \ autoconf perl-Thread-Queue perl-Text-Iconv automake GeoIP GeoIP-devel \ ImageMagick-devel ImageMagick libmemcached-devel libmemcached \ libevent-devel libevent lz4-devel lz4 librdkafka-devel librdkafka \ postgresql-devel postgresql libyaml libyaml-devel subversion-devel \ subversion 二,编译因为源里面没能提供而需要单独下载和编译的依赖库,如果源里面能提供符合 条件的包那么可以省略。 三,注意, openssl 需要支持 SM4 ,参考下方 OpenSSL 库 的说明,检查源或者自己编译的 openssl 是否支持。 -------------------------------------------------------------------------------- 编译jpeg 下载:https://www.ijg.org/ https://www.ijg.org/files/jpegsrc.v9d.tar.gz 编译命令 ./configure --prefix=/opt/jpeg make make install -------------------------------------------------------------------------------- 安装cmake工具 下载页面https://cmake.org/download/ 下载得到压缩包cmake-3.20.0-rc3.tar.gz,解压到/root/src/cmake-3.20.0-rc3 配置、编译: /root/src/cmake-3.20.0-rc3/bootstrap --prefix=/opt/cmake gmake make install -------------------------------------------------------------------------------- 安装automake 下载:automake-1.15.tar.gz 配置 ./configure --prefix=/opt/automake make make install 注:后面如果报错 按照https://blog.csdn.net/whatday/article/details/102473565修改报错的地方 -------------------------------------------------------------------------------- 编译GD库 下载链接:https://github-releases.githubusercontent.com/29669711/4993b100-7e88-11eb-879f-86529f61b87e?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210310%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210310T080537Z&X-Amz-Expires=300&X-Amz-Signature=30d9ecedc4de679fe550b84c7d890713a136007451fc7cfa8931125de3f0b1b8&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=29669711&response-content-disposition=attachment%3B%20filename%3Dlibgd-2.3.2.tar.gz&response-content-type=application%2Foctet-stream 我下载的版本是libgd-2.3.2.tar.gz,编译安装参数是: LIBJPEG_LIBS="-L/opt/jpeg/lib -Wl,--rpath=/opt/jpeg/lib" \ PKG_CONFIG_PATH=/opt/jpeg ./configure --prefix=/opt/libgd --with-zlib \ --with-png --with-freetype --with-jpeg=/opt/jpeg --with-xpm --with-tiff \ --with-webp PATH="/opt/automake/bin:$PATH" make make install -------------------------------------------------------------------------------- 下载libzip https://libzip.org/download/ https://libzip.org/download/libzip-1.7.3.tar.gz 配置和编译 mkdir -p build cd build /opt/cmake/bin/cmake .. -DCMAKE_INSTALL_PREFIX=/opt/libzip make make install -------------------------------------------------------------------------------- 编译安装https://github.com/kkos/oniguruma/releases/tag/v6.9.6的oniguruma库 ./configure --prefix=/opt/oniguruma && make && make install -------------------------------------------------------------------------------- 下载,安装libsodium https://doc.libsodium.org/installation curl -o libsodium-1.0.18-stable.tar.gz https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz 编译安装 ./configure --prefix=/opt/libsodium make make install -------------------------------------------------------------------------------- 安装libtidy https://github.com/htacg/tidy-html5/releases/tag/5.6.0 cd build/cmake /opt/cmake/bin/cmake ../.. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/opt/tidy make make install -------------------------------------------------------------------------------- Libmcrypt库:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/ cd libmcrypt-2.5.8 ./configure --prefix=/opt/libmcrypt make make install 三,编译安装PHP解释器等 我下载的版本是php-7.4.16 [root@localhost php-7.4.16]# ls appveyor ext README.md azure EXTENSIONS README.REDIST.BINS azure-pipelines.yml include run-tests.php build libs sapi buildconf libtool scripts buildconf.bat LICENSE setup.sh CODING_STANDARDS.md main tests config.log Makefile travis config.nice Makefile.fragments TSRM config.status Makefile.objects UPGRADING configure modules UPGRADING.INTERNALS configure.ac NEWS win32 configure_help.txt pear yum.sh CONTRIBUTING.md php.ini-development Zend docs php.ini-production 解压后的路径是/root/src/php-7.4.16 编译: PKG_CONFIG_PATH="/opt/jpeg/lib/pkgconfig/:/opt/libgd/lib/pkgconfig/:/opt/libzip/lib64/pkgconfig/:/opt/oniguruma/lib/pkgconfig/:/opt/libsodium/lib/pkgconfig/" \ CFLAGS="-I/opt/libgd/include -I/opt/jpeg/include" \ LDFLAGS="-L/opt/jpeg/lib -Wl,--rpath=/opt/jpeg/lib -L/opt/libgd/lib -Wl,--rpath=/opt/libgd/lib -Wl,--rpath=/opt/libzip/lib64 -Wl,--rpath=/opt/oniguruma/lib -Wl,--rpath=/opt/libsodium/lib -Wl,--rpath=/opt/tidy/lib" \ ./configure --prefix=/opt/php7.4 --enable-fpm --enable-gd --with-external-gd \ --with-jpeg --with-webp --with-xpm --with-freetype --enable-bcmath --with-zlib \ --with-pcre-jit --enable-sockets --enable-soap --with-pdo-mysql --with-mysql-sock \ --with-mysqli --enable-mysqlnd --with-openssl --with-zip --enable-mbstring \ --enable-intl --enable-pcntl --with-bz2 --enable-calendar --enable-sysvmsg \ --enable-sysvsem --enable-sysvshm --with-curl --enable-ftp --with-enchant \ --enable-exif --with-gmp --with-gettext --with-sodium --enable-dba --with-pspell \ --with-readline --with-snmp --with-xsl --enable-shmop --with-xmlrpc \ --with-tidy=/opt/tidy --with-pgsql --with-pdo-pgsql --enable-phpdbg \ --enable-phpdbg-webhelper --enable-phpdbg-readline --enable-sigchild \ --with-pear --enable-werror make -j 4 make install 开启Opcache扩展 修改/opt/php7.4/lib/php.ini添加zend_extension=opcache 修改: [opcache] ; Determines if Zend OPCache is enabled opcache.enable=1 四,独立扩展的编译和安装: -------------------------------------------------------------------------------- APCU扩展 http://pecl.php.net/package/apcu [root@localhost apcu-5.1.20]# pwd /root/src/apcu-5.1.20 操作: /opt/php7.4/bin/phpize ./configure --enable-apcu --with-php-config=/opt/php7.4/bin/php-config \ --prefix=/opt/php_apcu make make install 扩展二进制文件位于:/opt/php7.4/lib/php/extensions/no-debug-non-zts-20190902/apcu.so 修改/opt/php7.4/lib/php.ini添加extension=apcu -------------------------------------------------------------------------------- geoip扩展 http://pecl.php.net/package/geoip [root@localhost geoip-1.1.1]# pwd /root/src/geoip-1.1.1 编译: /opt/php7.4/bin/phpize ./configure --with-geoip --with-php-config=/opt/php7.4/bin/php-config \ --prefix=/opt/php_geoip make make install 二进制文件位置 /opt/php7.4/lib/php/extensions/no-debug-non-zts-20190902/ 修改/opt/php7.4/lib/php.ini添加extension=geoip -------------------------------------------------------------------------------- igbinary扩展 http://pecl.php.net/package/igbinary /opt/php7.4/bin/phpize ./configure --enable-igbinary --with-php-config=/opt/php7.4/bin/php-config \ --prefix=/opt/php_igbinary make make install 修改/opt/php7.4/lib/php.ini添加extension=igbinary -------------------------------------------------------------------------------- imagick扩展 http://pecl.php.net/package/imagick /opt/php7.4/bin/phpize LDFLAGS="-Wl,--rpath=/usr/lib64" ./configure --with-imagick=/usr \ --with-php-config=/opt/php7.4/bin/php-config --prefix=/opt/php_imagick make make install 修改/opt/php7.4/lib/php.ini添加extension=imagick -------------------------------------------------------------------------------- mcrypt扩展 扩展:http://pecl.php.net/package/mcrypt /opt/php7.4/bin/phpize LDFLAGS="-Wl,--rpath=/opt/libmcrypt/lib" ./configure \ --with-mcrypt=/opt/libmcrypt --with-php-config=/opt/php7.4/bin/php-config \ --prefix=/opt/php_mcrypt make && make install 修改/opt/php7.4/lib/php.ini添加extension=mcrypt -------------------------------------------------------------------------------- memcached扩展下载 http://pecl.php.net/package/memcached [root@localhost memcached-3.1.5]# pwd /root/src/memcached-3.1.5 编译 /opt/php7.4/bin/phpize ./configure --prefix=/opt/php_memcached --enable-memcached \ --with-php-config=/opt/php7.4/bin/php-config --enable-memcached-session \ --enable-memcached-igbinary --enable-memcached-json \ --enable-memcached-protocol --with-zlib-dir=/usr make && make install 修改/opt/php7.4/lib/php.ini添加extension=memcached -------------------------------------------------------------------------------- memcache扩展下载 http://pecl.php.net/package/memcache 下载: # pwd /root/src/memcache-4.0.5.2 /opt/php7.4/bin/phpize ./configure --prefix=/opt/php_memcache --enable-memcache \ -with-zlib-dir=/usr --with-php-config=/opt/php7.4/bin/php-config make && make install 修改/opt/php7.4/lib/php.ini添加extension=memcache -------------------------------------------------------------------------------- mongodb扩展 http://pecl.php.net/package/mongodb 编译 [root@localhost mongodb-1.9.0]# pwd /root/src/mongodb-1.9.0 [root@localhost mongodb-1.9.0]# /opt/php7.4/bin/phpize [root@localhost mongodb-1.9.0]# ./configure --prefix=/opt/php_mongodb --enable-mongodb --with-php-config=/opt/php7.4/bin/php-config [root@localhost mongodb-1.9.0]# make && make install 修改/opt/php7.4/lib/php.ini添加extension=mongodb -------------------------------------------------------------------------------- redis扩展 http://pecl.php.net/package/redis /root/src/redis-5.3.3 编译 /opt/php7.4/bin/phpize ./configure --prefix=/opt/php_redis \ --with-php-config=/opt/php7.4/bin/php-config --enable-redis \ --enable-redis-igbinary --enable-redis-lzf --enable-redis-lz4 \ --with-liblz4=/usr make && make install 修改/opt/php7.4/lib/php.ini添加extension=redis -------------------------------------------------------------------------------- yaml 扩展 *需要`yum install -y libyaml libyaml-devel`* 下载扩展 https://www.php.net/manual/zh/yaml.installation.php 命令 /opt/php7.4/bin/phpize ./configure --prefix=/opt/php_yaml --with-yaml \ --with-php-config=/opt/php7.4/bin/php-config make && make install 修改配置 php.ini 添加 extension=yaml -------------------------------------------------------------------------------- kafka扩展 http://pecl.php.net/package/rdkafka /root/src/rdkafka-5.0.0 /opt/php7.4/bin/phpize ./configure --prefix=/opt/php_rdkafka \ --with-php-config=/opt/php7.4/bin/php-config --with-rdkafka make && make install 修改/opt/php7.4/lib/php.ini添加extension=rdkafka -------------------------------------------------------------------------------- Swoole扩展,注意使用这个扩展需要确保关闭aop,不能开phptrace,不能用xdebug, 因为有冲突。 目前Swoole稳定版是4.4.x,下载: https://github.com/swoole/swoole-src/releases 编译安装: /opt/php7.4/bin/phpize PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig \ LDFLAGS="-L/opt/openssl/lib -lcrypto -ldl -pthread -lssl -Wl,--rpath=/opt/openssl/lib" \ CPPFLAGS="-I/opt/openssl/include" \ CXXFLAGS="-I/opt/openssl/include" \ ./configure --prefix=/opt/php_swoole \ --with-php-config=/opt/php7.4/bin/php-config --enable-sockets \ --enable-openssl --enable-http2 --enable-swoole --enable-mysqlnd make && make install 修改/opt/php7.4/lib/php.ini添加extension=swoole 注:在编译和调试编译条件时测试查看页面可以通过 /opt/php7.4/sbin/php-fpm -F -R 以前台进程方式启动一个 php-fpm 。如果本地有编译其他版本的 openssl ,这里最好也指定 LDFLAGS CPPFLAGS CXXFLAGS 。 以下是我本地安装好的 `phpinfo()` 截图: ![phpinfo()页面,swoole信息](php-swoole.jpg) -------------------------------------------------------------------------------- SVN 扩展 注:这个扩展目前暂时只有Beta版本能兼容php7.4。 https://pecl.php.net/package/svn 注:如果没有,如要安装 yum install -y subversion-devel subversion 解压: svn-2.0.3 /opt/php7.4/bin/phpize ./configure --with-php-config=/opt/php7.4/bin/php-config make && make install 需要调整 php.ini 增加 extension=svn -------------------------------------------------------------------------------- 五,最后php -m显示的模块、扩展(ldap如果出现错误,就不要使用了) # /opt/php7.4/bin/php -m [PHP Modules] apcu bcmath bz2 calendar Core ctype curl date dba dom enchant exif fileinfo filter ftp gd geoip gettext gmp hash iconv igbinary imagick intl json ldap libxml mbstring mcrypt memcache memcached mongodb mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_pgsql pdo_sqlite pgsql Phar phpdbg_webhelper posix pspell rdkafka readline redis Reflection session shmop SimpleXML snmp soap sockets sodium SPL sqlite3 standard svn swoole sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlrpc xmlwriter xsl yaml Zend OPcache zip zlib [Zend Modules] Zend OPcache 六,有些库如果要自己编译的话可以参考 -------------------------------------------------------------------------------- enchant 库 下载地址 https://github.com/AbiWord/enchant/releases 测试安装的版本: enchant-2.2.15.tar.gz ./configure --prefix=/home/work/app/enchant --enable-relocatable make make install -------------------------------------------------------------------------------- xml2库 下载 http://www.xmlsoft.org/downloads.html ./configure --prefix=/home/work/app/libxml2 --with-icu --with-zlib \ --with-lzma --with-python=../../app/python38/bin/python3 make && make install -------------------------------------------------------------------------------- OpenSSL 库 下载地址 https://www.openssl.org/source/ 编译安装 ./config --prefix=/opt/openssl make && make install 关于国密算法的说明 实测发现 OpenSSL 1.1.1i 也可以,但最好使用最新版本的 OpenSSL 1.1.1k 。通过下面的命令可以查看已经安装的 openssl 是否支持国密 SM4 openssl enc -list | grep sm 可以看到,最新版本支持国密的情况: [root@localhost openssl]# LD_LIBRARY_PATH=lib bin/openssl enc -list | grep sm -id-smime-alg-CMS3DESwrap -idea -idea-cbc -seed-ecb -seed-ofb -sm4 -sm4-cbc -sm4-cfb -sm4-ctr -sm4-ecb -sm4-ofb 有 `-sm4` 的 ciphers 存在。 [root@localhost openssl]# LD_LIBRARY_PATH=lib bin/openssl dgst -list | grep sm -shake256 -sm3 -ssl3-md5 有支持 `-sm3` 。 PHP编译的时候带上自己编译的 openssl 以支持 SM4 的方法是在编译时指定包含和链接的 openssl 位置。比如通过添加环境变量: OPENSSL_LIBS="-L/opt/openssl/lib -lcrypto -ldl -pthread -lssl -Wl,--rpath=/opt/openssl/lib" OPENSSL_CFLAGS="-I/opt/openssl/include" 或者: PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig 上面的路径 `/opt/openssl` 替换成实际上安装的 openssl 的路径。注意如果之前编译过,则需要执行 make clean 然后重新编译 php 。编译成功后可以在`phpinfo()`函数的输出上检查是否加载了新的 openssl 。成功加载的话是可以看到新版本的 openssl 的。 ![phpinfo()页面,openssl信息](php-openssl.jpg) 接下来最好检查下, PHP 程序是不是确实支持了 SM4 相关算法。执行以下命令应该返回一样的结果: [root@localhost ~]# /opt/php7.4/bin/php -r 'var_dump(openssl_get_cipher_methods());' | grep sm4 string(7) "sm4-cbc" string(7) "sm4-cfb" string(7) "sm4-ctr" string(7) "sm4-ecb" string(7) "sm4-ofb" 其中的 `/opt/php7.4` 是安装 PHP 的路径。 PHP 通过 openssl 使用 SM4 示例 ```PHP $key = openssl_random_pseudo_bytes(16); $ivlen = openssl_cipher_iv_length("sm4"); $iv = str_repeat("\0", $ivlen); $plaintext = "Hello, world."; $ciphertext = openssl_encrypt($plaintext, "sm4", $key, $options=0, $iv); $original_plaintext = openssl_decrypt($ciphertext, "sm4", $key, $options=0, $iv); printf("sms4enc(\"%s\") = %s\n", $plaintext, bin2hex($ciphertext)); printf("sms4dec(%s) = \"%s\"\n", bin2hex($ciphertext), $original_plaintext); ``` 程序执行效果: [root@localhost ~]# vi test_sm4.php [root@localhost ~]# /opt/php7.4/bin/php test_sm4.php sms4enc("Hello, world.") = 345657474f43464c754b4d3931667a515767764161773d3d sms4dec(345657474f43464c754b4d3931667a515767764161773d3d) = "Hello, world." -------------------------------------------------------------------------------- Zlib库 ./configure --prefix=/home/work/app/zlib && make && make install -------------------------------------------------------------------------------- CURL 库 ./configure --prefix=/home/work/app/curl && make && make install -------------------------------------------------------------------------------- TIFF 库 下载:http://www.libtiff.org/ ```shell ./configure --prefix=/home/work/app/tiff --enable-rpath \ --enable-cxx --with-zlib-include-dir=/home/work/app/zlib/include \ --with-zlib-lib-dir=/home/work/app/zlib/lib \ CFLAGS="-I/home/work/app/zlib/include" \ LDFLAGS="-L/home/work/app/zlib/lib -Wl,--rpath=/home/work/app/zlib/lib" \ CPPFLAGS="-I/home/work/app/zlib/include" make && make install ``` -------------------------------------------------------------------------------- webp 库 下载地址 https://gitee.com/mirrors/libwebp 指定 ACLOCAL_PATH ,如果单独安装了 libtool ```shell ACLOCAL_PATH=/home/work/app/libtool/share/aclocal ./autogen.sh LDFLAGS="-Wl,--rpath=/home/work/app/tiff/lib" \ ./configure --prefix=/home/work/app/libwebp --enable-swap-16bit-csp \ --enable-libwebpmux --enable-libwebpdecoder --enable-libwebpextras \ --with-tiffincludedir=/home/work/app/tiff/include \ --with-tifflibdir=/home/work/app/tiff/lib make && make install ``` -------------------------------------------------------------------------------- GD 库 ```shell #!/bin/bash TIFF=/home/work/app/tiff WEBP=/home/work/app/libwebp ./configure --prefix=/home/work/app/libgd --enable-werror \ --with-zlib=/home/work/app/zlib --with-png --with-freetype \ --with-fontconfig --with-jpeg --with-xpm --with-tiff=$TIFF \ --with-webp=$WEBP \ PKG_CONFIG_PATH=/home/work/app/zlib/pkgconfig \ CFLAGS="-I/home/work/app/zlib/include -I$TIFF/include" \ LDFLAGS="-L/home/work/app/zlib/lib -Wl,--rpath=/home/work/app/zlib/lib -L$TIFF/lib -Wl,--rpath=$TIFF/lib -Wl,--rpath=$WEBP/lib" make && make install ``` -------------------------------------------------------------------------------- ICU 库 下载 http://site.icu-project.org/download/ 解压后生成icu文件夹,进去。这里我用的是 icu4c-50_2-src.tgz ,需要进入 source 目录。 ```shell cd /home/work/src/icu/source ./configure --prefix=/home/work/app/libicu --enable-static --enable-rpath make && make install ``` -------------------------------------------------------------------------------- 手工编译 PostgreSQL 作为编译 PHP 的依赖库 下载: https://www.postgresql.org/ftp/source/ https://ftp.postgresql.org/pub/source/v13.2/postgresql-13.2.tar.gz 编译步骤 ```shell mkdir build_dir && cd build_dir /home/work/src/postgresql/configure --prefix=/home/work/app/postgresql --enable-nls --with-icu --with-ldap --with-libxml --with-libxslt make && make install ``` -------------------------------------------------------------------------------- 编译 aspell http://aspell.net/ ./configure --prefix=/home/work/app/aspell && make && make install -------------------------------------------------------------------------------- SNMP 下载地址 http://www.net-snmp.org,解压 /home/work/src/net-snmp-5.9 编译 ```shell ./configure --prefix=/home/work/app/net-snmp --without-perl-modules make && make install ``` -------------------------------------------------------------------------------- 安装 libxslt 下载地址 http://www.linuxfromscratch.org/blfs/view/svn/general/libxslt.html ```shell ./configure --prefix=/home/work/app/libxslt make && make install ``` -------------------------------------------------------------------------------- Freetype 安装 下载网站 https://www.freetype.org/download.html ```shell CFLAGS="-I/opt/bzip2/include" \ LDFLAGS="-Wl,--rpath=/opt/libpng/lib -Wl,--rpath=/opt/zlib/lib" \ CPPFLAGS="-I/opt/bzip2/include" \ PKG_CONFIG_PATH="/opt/libpng/lib/pkgconfig/:/opt/zlib/lib/pkgconfig/" \ ./configure --prefix=/opt/freetype --enable-biarch-config \ --enable-freetype-config && make && make install ``` -------------------------------------------------------------------------------- 根据需要,后期可以添加 `SkyAPM-php-sdk` 扩展。假设软件安装在目录 `/opt` 下面(PHP安装目录 `/opt/php7.4` ),编译、安装和配置的步骤可以参考以下内容。 **安装 SkyAPM-php-sdk** 1. 准备SDK源码。 `curl -Lo v4.2.0.tar.gz https://github.com/SkyAPM/SkyAPM-php-sdk/archive/v4.2.0.tar.gz` 。下载之后可以解压出来。 2. 准备GRPC源码。通过git克隆指定的分支和所有依赖模块到本地目录下: `git clone --depth=1 --recurse-submodules -b v1.34.x https://github.com/grpc/grpc /opt/grpc-src-1.34.x` ,不克隆完里面的git模块是编译不了的。 3. 编译GRPC。 `cd /opt/grpc-src-1.34.x` , `mkdir -p cmake/build && cd cmake/build` ;然后执行 `cmake ../.. -DCMAKE_BUILD_TYPE=Release`,编译 `cmake --build .` 。编译出二进制文件就行了,不需要额外进行安装。 4. 准备C++ Boost库。 `https://sourceforge.net/projects/boost/` ,我本地构建使用的 `boost_1_74_0.tar.gz` 。 `tar -axf boost_1_74_0.tar.gz` , `cp -r boost_1_74_0 /opt/` ,这个库是头文件库,不需要安装。 5. 需要curl库。如果根据上面文档已经安装好了curl库,可以省略。如果没有则需要安装。 6. 编译扩展。cd进入SDK源码目录,执行 `/opt/php7.4/bin/phpize` ,然后参考下面的配置安装: ```shell CFLAGS="-I/opt/boost_1_74_0" \ CXXFLAGS="-I/opt/boost_1_74_0" \ ./configure --prefix=/opt/SkyAPM-php-sdk \ --with-php-config=/opt/php7.4/bin/php-config \ --enable-skywalking \ --with-grpc=/opt/grpc-src-1.34.x && make make install ``` *备注:下载的v4.2.0.tar.gz用的是 `--with-grpc=` ,github的master分支用的是 `--with-grpc-src=` 。* 执行 `make install` 成功会输出PHP扩展安装位置,去目录下查看应该有文件 `skywalking.so` 。 **配置** 参考SDK源码内的文档 `SkyAPM-php-sdk/docs/CONFIG.md` 配置PHP配置文件 `php.ini` 的内容。 `php.ini` 默认在 `/opt/php7.4/lib` 目录下,大约950行 `Module Settings` 之前的一系列 `extension=` 的地方,添加: extension=skywalking 这样可以令PHP启动时加载共享对象库 `skywalking.so` 。 方便维护,把下面的配置内容在 `Module Settings` 里面新增一个块 `[skywalking]` ,填写: ; 启用 SkyWalking skywalking.enable = 1 ; 设置 skyWalking 控制器版本,5、6、7或8 skywalking.version = 8 ; 设置app code skywalking.app_code = the_skywalking_php_agent ; GRPC地址 skywalking.grpc=127.0.0.1:11800 其中的RPC地址需要根据实际情况填写。完成后执行 `/opt/php7.4/bin/php -m` 应该可以看到模块skywalking存在。然后,启动FPM的时候需要新增 `--nodaemonize` 参数,以前台进程的方式运行php-fpm。 -------------------------------------------------------------------------------- PHP安装Yac扩展 扩展源码从 [这里下载](https://pecl.php.net/package/yac) 。下载后解压、配置接着编译和安装。操作参考: # tar -axf yac-2.3.1.tgz # cp -r yac-2.3.1 /opt/yac-2.3.1-src && cd /opt/yac-2.3.1-src # phpize # ./configure --help # ./configure --enable-yac # make && make install 安装成功之后到PHP扩展目录,位于 `/lib/php/extensions/no-debug-non-zts-<年月日>/` 查看应该有 `yac.so` 。然后修改配置文件 `vim /lib/php.ini` ,在“Dynamic Extensions”里面添加 `extension=yac` 或直接指定文件路径 `extension=<路径>/yac.so` 。最后使用 `kill -USR2 ` 重启PHP-FPM以加载新增扩展。 phpinfo支持情况: ![phpinfo()页面,yac信息](yac.png) php命令查看yac支持情况: $ php --ri yac yac yac support => enabled Version => 2.3.1 Shared Memory => mmap Serializer => php Directive => Local Value => Master Value yac.enable => On => On yac.debug => Off => Off yac.keys_memory_size => 4M => 4M yac.values_memory_size => 64M => 64M yac.compress_threshold => -1 => -1 yac.enable_cli => 0 => 0 yac.serializer => php => php 这几个值根据电脑内存情况,可以适当改大点, `enable_cli` 可以开启以允许php命令执行的脚本也能用yac(下面的配置追加到 `php.ini` 配置文件,修改配置需要重启PHP-FPM): [yac] yac.keys_memory_size = 100M yac.values_memory_size = 200M yac.enable_cli = 1 另外,如果电脑上有安装其它字符串序列化的库,那么 `./configure` 时也可以指定开启这几个支持: --with-system-fastlz --enable-json --enable-msgpack --enable-igbinary