php 版本升级到7.1.3后,发现 mcrypt加密算法不能用了。推荐的替代方案就是openssl,现记录一下其安装过程。
1. 下载php源码包
首先确定使用的php版本,php -v,也可以在phpinfo()中查看。
如图,我的版本是7.1.3。
下载并解压,进入PHP的openssl扩展模块目录
$wget http://mirrors.sohu.com/php/php-7.1.3.tar.gz$tar zxvf php-7.1.3.tar.gz$cd php-7.1.3/ext/openssl
编译安装
# $ which phpize 找到phpize应用位置/usr/bin/phpize# 然后执行$ /usr/bin/phpize# 执行后,发现错误 无法找到config.m4 ,config0.m4就是config.m4。直接重命名$ cp config0.m4 config.m4# 重新执行phpize$ /usr/bin/phpize# $ which php-config 找到php-config应用位置/usr/bin/php-config# 然后执行$ ./configure --with-openssl --with-php-config=/usr/bin/php-config$ make$ make test$ sudo make install
安装完成后,会返回一个.so文件(openssl.so)的目录。在此目录下把openssl.so文件拷贝到你在php.ini中指定的extension_dir下(在php.ini文件中查找:extension_dir =或者打印出phpinfo()),我这里的目录是/usr/lib/php/20160303
在php配置文件添加 openssl 扩展
$/etc/php/7.1/mods-available$touch openssl.ini$sudo vim openssl.ini
文件内容为
; configuration for php openssl module; priority=20extension=openssl.so
重启
sudo /etc/init.d/php7.1-fpmrestartsudo service nginxrestart
再次打印出phpinfo(),可以看到openssl相关的信息。