业务性能到达了瓶颈,代码优化已经无法显著提升程序性能,最终选择了进行 PHP 版本升级,原来的版本是 PHP5.4,打算升级至最新的稳定版本7.2

  • 下载 PHP 并解压,切换到 PHP 目录
wget http://php.net/get/php-7.2.1.tar.gz/from/this/mirror
tar zxvf mirror
cd php-7.2.1/
  • 生成 Makefile
./configure  --prefix=/usr/local/php72  --with-config-file-path=/usr/local/php72/etc  --with-config-file-scan-dir=/usr/local/php72/etc/php.d  --with-apxs2=/usr/local/apache/bin/apxs  --enable-opcache  --disable-fileinfo  --enable-mysqlnd  --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd  --with-iconv-dir=/usr/local  --with-freetype-dir=/usr/local/freetype  --with-jpeg-dir  --with-png-dir  --with-zlib  --with-libxml-dir=/usr  --enable-xml  --disable-rpath  --enable-bcmath  --enable-shmop  --enable-exif  --enable-sysvsem  --enable-inline-optimization  --with-curl=/usr/local  --enable-mbregex  --enable-mbstring  --with-mcrypt  --with-gd  --enable-gd-native-ttf  --with-openssl  --with-mhash  --enable-pcntl  --enable-sockets  --with-xmlrpc  --enable-ftp  --enable-intl  --with-xsl  --with-gettext  --enable-zip  --enable-soap  --disable-debug

因为已经安装过其他版本的PHP所以安装至 /usr/local/php72 我的PHP是以模块的形式被 Apache 所加载,所以使用 with-apxs2=/usr/local/apache/bin/apxs 生成模块.之前已经安装过 PHP 所以之前并没有出现什么问题.

  • 编译与安装
make && make install

过程中出现了 undefined reference to 'libiconv_open' undefined reference to 'libiconv' undefined reference to 'libiconv_close'
编辑 Makefile 找到 EXTRA_LIBS = -lcrypt -lz -lexslt -lresolv -lcrypt -lrt -lstdc++ -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lz -lbz2 -ldl -lm -licui18n -licuuc -licudata -ldl -lm -licuio -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxslt -lxml2 -lz -ldl -lm -lssl -lcrypto -lcrypt 在改行行尾添加 -liconv 继续编译 make && make install

  • 配置
    拷贝配置文件至安装目录 cp php.ini-development /usr/local/php72/etc/php.ini

编辑 apache 配置文件 将 LoadModule php5_module modules/libphp5.so 屏蔽,开启 LoadModule php7_module modules/libphp7.so

service httpd restart

搞定.