1.下载
# wget http://php.net/get/php-7.1.4.tar.gz/from/a/mirror
或者# wget http://am1.php.net/distributions/php-7.1.4.tar.gz
前者得到一个mirror文件,后者得到php-7.1.4.tar.gz,均可以通过tar解压
2.解压
# tar zxvf php-7.1.4.tar.gz 或 tar zxvf mirror
# cd php-7.1.4
3.查看安装帮助,执行配置脚本来进行编译预处理
# ./configure --help
# ./configure --prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
4.编译预处理可能会出现一些error,一般是缺少依赖包的原因,根据提示安装即可
# apt-get install libxml2 libxml2-dev
# apt-get install openssl
//configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
#apt-get install libssl-dev
#apt-get install libgtk2.0-dev
//configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
// RetHat CentOS or Fedora 使用下面安装命令
# yum install curl curl-devel
// Debian or Ubuntu使用下面的安装命令
# apt-get install curl
# apt-get install libcurl4-gnutls-dev
//configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
# apt-get install libxslt-dev
5.预处理通过之后就可以make编译了
# make && make install
6.配置php
编译安装成功后,一般可以在usr/local找到安装的php
//php.ini
# cp php.ini-development /usr/local/php/lib/php.ini
//php-fpm
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm 或cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置
7.启动
//查看php版本
# /usr/local/php/bin/php -v
# /etc/init.d/php-fpm start
或 # service php-fpm start
//php-fpm 可用参数 start|stop|force-quit|restart|reload|status
//若权限不足需要需要加上执行权限
chmod +x /etc/init.d/php-fpm
//Starting php-fpm [06-May-2017 14:10:49] ERROR: [pool www] cannot get gid for group 'nobody'
[06-May-2017 14:10:49] ERROR: FPM initialization failed
failed
//确定php-fpm配置文件的路径,执行
#ps -aux | grep php-fpm
在安装目录的etc下有个php-fpm.d目录(如/usr/local/php/etc/php-fpm.d),打开这个目录后,找到www.conf文件,修改该文件里:
user = 启动fpm的用户名
group = 启动fpm的用户所在用户组
//不推荐用root用户启动,应当新建用户
#adduser phpq //新建phpq用户
#passwd phpq //给phpq用户设置密码
#groupadd test //新建test工作组
//The program 'php' can be found in the following packages:
* php7.0-cli
* hhvm
sudo apt install php
sudo apt install hhvm