说明:
安装使用的是阿里云ECS ubuntu14.04系统。操作过程中可能不同版本系统,会有些差异。具体问题还请网上查询相关解决办法。相关源码包会不断更新,假如看到本文时间比较久,还是建议直接上官网下载最近的版本。linux下手动编译安装用户软件,源码放在/usr/local/src中,安装路径在/usr/local/下。如果只是单独编译安装php,还需要相关的编译工具和库,参考另一篇编译安装nginx文章。
前期准备:
1.安装curl库和mcrypt库
编译安装PHP7以上的源码,支持curl和mcrypt功能,需要单独安装这两个库。其他是否需要安装,未涉及不确定。以具体操作为准。
curl源码下载地址:https://curl.haxx.se/download/
wget https://curl.haxx.se/download/curl-7.50.0.tar.gz tar -zxvf curl-7.50.0.tar.gz cd curl-7.50.0 ./configure make && make install
这里mcrypt库直接采用apt-get安装如下:
apt-get install libmcrypt-dev
2. 编译安装php
下载各版本源码地址:http://php.net/get/php-7.1.17.tar.gz/from/a/mirror
wget http://cn2.php.net/distributions/php-7.1.17.tar.gz tar -zxvf php-7.1.17.tar.gz cd php-7.1.17 ./configure --prefix=/usr/local \ --with-mcrypt=/usr/include \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv \ --with-zlib \ --with-openssl \ --with-curl \ --enable-fpm \ --enable-mbstring \ --with-mysql=/usr/share/mysql/ make && make install
具体编译配置参数可以使用命令:./configure --help查看
也可以参考这篇文章介绍:https://segmentfault.com/a/1190000002717262
如果是早起版本php配合nginx使用,需要单独安装php-fpm。后面php版本直接包含了php-fpm功能,只要编译时打开即可。具体说明可参照php-fpm官网:https://php-fpm.org/download/
安装完成可以使用php -m 命令查看添加的模块。