PHP7(zts 线程安全版)编译安装(支持多线程pthreads)

1、安装PHP7:
wget http://ar2.php.net/get/php-7.0.3.tar.gz/from/this/mirror -O php.tar.gz
tar -zxvf php.tar.gz
cd php


./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-pear --with-gettext --enable-session --with-curl --with-openssl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-gdbm --enable-fileinfo --enable-maintainer-zts


make
make install


遇到问题:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
需要安装:
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/libmcrypt-2.5.8
./configure --prefix=/usr/local
make
make install


遇到问题:
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解决:
vim /etc/ld.so.conf.d/local.conf     # 编辑库文件
/usr/local/lib                       # 添加该行
:wq                                  # 保存退出
ldconfig -v                          # 使之生效


遇到问题:
configure: error: DBA: Could not find necessary header file(s).
解决:
yum install gdbm-devel


2、安装多线程库:
cd /usr/local/php7/bin
./pecl install pthreads


或手动编译安装:
wget http://119.90.25.33/pecl.php.net/get/pthreads-3.1.6.tgz
tar -zxvf
cd pthreads-3.1.6
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make && make install
编辑/usr/local/php/lib/php.ini加上extension=pthreads.so


3、配置文件
在/usr/local/php7/etc/目录下新建php.ini文件,初始文件可在php源码的根目录找到php.ini-production
然后编辑php.ini,在末尾增加


extension="pthreads.so"
安装完成


查看安装是否成功
运行
/usr/local/php7/bin/php -m


4、php-fpm
支持 PHP 7 的 pthreads v3 只支持通过 cli 命令行来调用,不支持其他的 sapi,所以
执行/usr/local/php7/sbin/php-fpm 出错:
[17-Nov-2016 14:35:20] NOTICE: PHP message: PHP Fatal error:  The fpm-fcgi SAPI is not supported by pthreads in Unknown on line 0
[17-Nov-2016 14:35:20] NOTICE: PHP message: PHP Fatal error:  Unable to start pthreads module in Unknown on line 0


解决:
CLI模式下,php会优先读取php-cli.ini,如果没找到会使用php.ini,SO:
【1】cp php.ini php-cli.ini // extension=/..(路径)../pthreads.so
【2】编辑原来的php.ini文件注释掉pthreads扩展 // ;extension=/..(路径)../pthreads.so
这样CLI模式下php-cli.ini生效,而php-fpm不会读php-cli.ini


添加PHP编译时的fpm用户和组:
groupadd nginx
useradd -g nginx nginx


5.设置php-fpm开机启动:
PHP-FPM SHELL脚本  放到/etc/init.d/下 取名php-fpm
##---start ---
#!/bin/bash
# php-fpm startup script for the php-fpm
# php-fpm version:5.5.0-alpha6
# chkconfig: - 85 15
# description: php-fpm is very good
# processname: php-fpm
# pidfile: /var/run/php-fpm.pid
# config: /usr/local/php/etc/php-fpm.conf


php_command=/usr/local/php7/sbin/php-fpm
php_config=/usr/local/php7/etc/php-fpm.conf
php_pid=/usr/local/php7/var/run/php-fpm.pid
RETVAL=0
prog="php-fpm"


#start function
php_fpm_start() {
    /usr/local/php7/sbin/php-fpm -c /usr/local/php7/etc/php.ini -y /usr/local/php7/etc/php-fpm.conf
}


start(){
    if [ -e $php_pid  ]
    then
    echo "php-fpm already start..."
    exit 1
    fi
    php_fpm_start
}


stop(){
    if [ -e $php_pid ]
    then
    parent_pid=`cat $php_pid`
    all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
    for pid in $all_pid
    do
            kill $pid
        done
        kill $parent_pid
    fi
    exit 1
}


restart(){
    stop
    start
}


# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|status}"
        exit 1
esac
exit $RETVAL


##----end -----




##  添加执行权限  
chmod a+x /etc/init.d/php-fpm


##  加入服务
chkconfig --add php-fpm


##   开机自启 
chkconfig php-fpm on




加入全局变量:


修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/php7/bin:/usr/local/nginx/sbin
export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。

猜你喜欢

转载自blog.csdn.net/u012322399/article/details/80949101