下载:

    https://www.php.net/downloads.php
    7.4: https://www.php.net/distributions/php-7.4.4.tar.gz
    7.2: https://www.php.net/distributions/php-7.2.20.tar.gz

安装依赖

    yum -y install gcc
    yum -y install libxslt libxslt-devel
    yum -y install readline-devel
    yum -y install gmp-devel
    yum -y install freetype-devel
    yum -y install libpng
    yum -y install libpng-devel
    yum -y install libjpeg-devel
    yum -y install curl-devel
    yum -y install bzip2 bzip2-devel
    yum -y install opensll
    yum -y install openssl-devel
    yum -y install libxml2-devel

manul install

  https://github.com/kkos/oniguruma

配置

./configure
–prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc
–enable-fpm
–with-fpm-user=nobody
–with-fpm-group=nobody
–enable-inline-optimization
–disable-debug
–disable-rpath
–enable-shared
–enable-soap
–with-libxml-dir
–with-xmlrpc
–with-openssl
–with-mhash
–with-pcre-regex
–with-zlib
–enable-bcmath
–with-iconv
–with-bz2
–enable-calendar
–with-curl
–with-cdb
–enable-dom
–enable-pcntl
–enable-exif
–enable-fileinfo
–enable-filter
–with-pcre-dir
–enable-ftp
–with-gd
–with-openssl-dir
–with-jpeg-dir
–with-png-dir
–with-zlib-dir
–with-freetype-dir
–enable-gd-jis-conv
–with-gettext
–with-gmp
–with-mhash
–enable-json
–enable-mbstring
–enable-mbregex
–enable-mbregex-backtrack
–with-libmbfl
–with-onig
–enable-pdo
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd
–with-zlib-dir
–with-readline
–enable-session
–enable-shmop
–enable-simplexml
–enable-sockets
–enable-sysvmsg
–enable-sysvsem
–enable-sysvshm
–enable-wddx
–with-libxml-dir
–with-xsl
–enable-zip
–enable-mysqlnd-compression-support
–enable-opcache

编译&&安装

    make && make install

开机自启动文件/etc/init.d/php-fpm

init.d/php-fpm

赋予脚本可执行权限

将php-fpm服务加入chkconfig管理列表

    chmod a+x /etc/init.d/php-fpm&&chkconfig --add /etc/init.d/php-fpm&&chkconfig php-fpm on

    systemctl start php-fpm

运行php-fpm

    sudo php-fpm -R 或者 systemctl start php-fpm.service

让Nginx支持php在nginx.conf中添加

    location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ =404;
         }
         
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9001;  
            fastcgi_index index.php;  
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
            include fastcgi_params;  
        }
  1. Centos 7 安装PHP 7 –skip-broken 问题解决:即运行yum clean all即可
  2. 参考文章CentOS 7 安装 PHP 7
  3. undefined reference to libiconv问题即则编辑Makefile文件找到 EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -lssl -lcrypto -lfreetype -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lssl -lcrypto -lcrypt 在最后添加 -liconv
  4. 安装目录在/usr/local/php/
  5. 将源码目录下的php.ini-development拷贝到/etc目录下:cp php.ini-development /etc/php.ini