CentOs7编译安装PHP7.2

2019-08-21  本文已影响0人  ysnows

下载:

    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

配置

    ./configure \
    --prefix=/usr/local/php \
    --with-config-file-path=/etc \
    --enable-fpm \
    --with-fpm-user=nginx  \
    --with-fpm-group=nginx \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared  \
    --enable-soap \
    --with-libxml-dir \
    --with-xmlrpc \
    --with-openssl \
    --with-mhash \
    --with-pcre-regex \
    --with-sqlite3 \
    --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-pdo-sqlite \
    --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 \
    --with-pear \
    --enable-opcache

编译&&安装

    make && make install

查看php-fpm配置文件,一般在:/usr/local/php/etc目录下,也可通过命令查找:find / -name php-fpm.conf

开机自启动文件/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
上一篇下一篇

猜你喜欢

热点阅读