本次安装基于系统CentOS Linux release 7.2.1511 (Core)

1、环境配置

安装前的环境准备:

  1. ##安装make,已安装,可省略
  2. yum -y install gcc automake autoconf libtool make
  3. ##安装gcc g++ glibc库
  4. yum -y install gcc gcc-c++ glibc
  5. ##安装所需的包
  6. yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

安装的包有些多,以上安装可分批或者一个一个进行,如yum -y install libmcrypt-devel,一般来说均可安装成功,如果失败可多试几次。

2、PHP编译安装

  1. ##创建工具目录
  2. mkdir /tools
  3. ##下载源码
  4. wget http://am1.php.net/distributions/php-7.2.21.tar.gz
  5. ##解压
  6. tar -zxvf php-7.2.21.tar.gz
  7. ##创建安装目录
  8. mkdir /server/php7.2
  9. cd /tools/php-7.2.21/
  10. ## 编译前配置
  11. ./configure --prefix=/server/php7.2 --with-config-file-path=/server/php7.2 --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --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-sysvshm --enable-xml --enable-zip --with-ldap
  12. ##编译时间略长,耐心等待
  13. make
  14. ##安装
  15. make install

3、配置php相关文件

  1. ##php.ini,编译配置时配在php7/etc目录下
  2. cp /tools/php-7.2.21/php.ini-development /server/php7.2/php.ini
  3. ##php-fpm.conf
  4. cp /server/php7.2/etc/php-fpm.conf.default /server/php7.2/etc/php-fpm.conf
  5. ##www.conf
  6. cp /server/php7.2/etc/php-fpm.d/www.conf.default /server/php7.2/etc/php-fpm.d/www.conf

4、设置php环境变量

  1. $vim /etc/profile
  2. ##加上下面这句话
  3. export PATH=/server/php7.2/bin:/server/php7.2/sbin:$PATH
  4. source /etc/profile
  5. php -v
  6. PHP 7.2.21 (fpm-fcgi) (built: Aug 12 2019 18:33:21)
  7. Copyright (c) 1997-2018 The PHP Group
  8. Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

5、启动php

  1. /server/php7.2/sbin/php-fpm
  2. ##检查进程是否启动
  3. ps -ef | grep php
  4. root 41963 1 0 18:04 ? 00:00:00 php-fpm: master process (/home/test/php7/etc/php-fpm.conf)
  5. nginx 41964 41963 0 18:04 ? 00:00:00 php-fpm: pool www
  6. nginx 41965 41963 0 18:04 ? 00:00:00 php-fpm: pool www
  7. ##检查端口9000是否活着
  8. netstat -anp | grep 9000
  9. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 41963/php-fpm: mast

6、多版本配置

  1. ##打开配置文件
  2. vim /server/php7.2/etc/php-fpm.d/www.conf
  3. ##修改,端口自定义
  4. listen = 127.0.0.1:9001
  5. // 启动php-fpm
  6. /server/php7.2/sbin/php-fpm -c /server/php7.2/etc/php-fpm.conf