下载:

    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

配置

./configure \
--prefix=/Users/ysnows/var/php74 \
--with-config-file-path=/Users/ysnows/var/php74/etc \
--enable-fpm \
--with-fpm-user=ysnows  \
--with-fpm-group=admin \
--enable-inline-optimization \
--with-iconv=$(brew --prefix libiconv) \
--enable-opcache

编译&&安装

    make && make install

config info

Installing shared extensions:     /Users/ysnows/var/php74/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /Users/ysnows/var/php74/bin/
Installing PHP CLI man page:      /Users/ysnows/var/php74/php/man/man1/
Installing PHP FPM binary:        /Users/ysnows/var/php74/sbin/
Installing PHP FPM defconfig:     /Users/ysnows/var/php74/etc/
Installing PHP FPM man page:      /Users/ysnows/var/php74/php/man/man8/
Installing PHP FPM status page:   /Users/ysnows/var/php74/php/php/fpm/
Installing phpdbg binary:         /Users/ysnows/var/php74/bin/
Installing phpdbg man page:       /Users/ysnows/var/php74/php/man/man1/
Installing PHP CGI binary:        /Users/ysnows/var/php74/bin/
Installing PHP CGI man page:      /Users/ysnows/var/php74/php/man/man1/
Installing build environment:     /Users/ysnows/var/php74/lib/php/build/
Installing header files:          /Users/ysnows/var/php74/include/php/
Installing helper programs:       /Users/ysnows/var/php74/bin/
program: phpize
program: php-config
Installing man pages:             /Users/ysnows/var/php74/php/man/man1/
page: phpize.1
page: php-config.1
/Users/ysnows/var/source/php-7.4.4/build/shtool install -c ext/phar/phar.phar /Users/ysnows/var/php74/bin
ln -s -f phar.phar /Users/ysnows/var/php74/bin/phar
Installing PDO headers:           /Users/ysnows/var/php74/include/php/ext/pdo/

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

    #!/bin/sh  
    # chkconfig:   2345 15 95
    
    # description:  PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
    
    # with some additional features useful for sites of any size, especially busier sites.
    # DateTime: 2016-09-20
    
    # Source function library.  
    . /etc/rc.d/init.d/functions  
    
    # Source networking configuration.  
    . /etc/sysconfig/network  
    
    # Check that networking is up.  
    [ "$NETWORKING" = "no" ] && exit 0  
    
    phpfpm="/usr/local/php/sbin/php-fpm"  
    prog=$(basename ${phpfpm})  
    
    lockfile=/var/lock/subsys/phpfpm
    
    start() {  
        [ -x ${phpfpm} ] || exit 5  
        echo -n $"Starting $prog: "  
        daemon ${phpfpm}
        retval=$?  
        echo  
        [ $retval -eq 0 ] && touch $lockfile  
        return $retval  
    }  
    
    stop() {  
        echo -n $"Stopping $prog: "  
        killproc $prog -QUIT  
        retval=$?  
        echo  
        [ $retval -eq 0 ] && rm -f $lockfile  
        return $retval  
    }  
    
    restart() {  
        configtest || return $?  
        stop  
        start  
    }  
    
    reload() {  
        configtest || return $?  
        echo -n $"Reloading $prog: "  
        killproc ${phpfpm} -HUP  
        RETVAL=$?  
        echo  
    }  
    
    force_reload() {  
        restart  
    }  
    
    configtest() {  
      ${phpfpm} -t
    }  
    
    rh_status() {  
        status $prog  
    }  
    
    rh_status_q() {  
        rh_status >/dev/null 2>&1  
    }  
    
    case "$1" in  
        start)  
            rh_status_q && exit 0  
            $1  
            ;;  
        stop)  
            rh_status_q || exit 0  
            $1  
            ;;  
        restart|configtest)  
            $1  
            ;;  
        reload)  
            rh_status_q || exit 7  
            $1  
            ;;  
        status)  
            rh_status  
            ;;  
        *)  
            echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"  
            exit 2  
     esac    

赋予脚本可执行权限

    chmod a+x /etc/init.d/php-fpm

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

    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