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命令查看是否添加成功。




注意,Mac下编译安装PHP7会出现下列问题:


过时:{
configure: error: Cannot find OpenSSL's <evp.h>
解决办法:安装openssl:
wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz
tar -zxvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
./config --prefix=/usr/local/openssl
目录下找到Makefile这个文件,用编辑器打开查找,将darwin-i386-cc替换成darwin64-x86_64-cc,保存
sudo make
sudo make install
[sudo rm -rf /usr/bin/openssl 删除自带的openssl]
sudo ln -s /usr/local/openssl/bin/openssl /usr/local/bin/openssl 
}
替代方案:
brew install openssl
加入参数:--with-openssl=/usr/local/opt/openssl


./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=/usr/local/opt/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




configure: error: DBA: Could not find necessary header file(s).
➜  php-7.0.13 brew install gdbm


configure: error: jpeglib.h not found.
➜  php-7.0.13 brew install libpng libjpeg


configure: error: freetype-config not found.
➜  php-7.0.13 brew install freetype


configure: error: Cannot locate header file libintl.h
➜  php-7.0.13 brew install gettext
编辑configure文件(php):
将:for i in $PHP_GETTEXT /usr/local /usr ; do
更改为:for i in $PHP_GETTEXT /usr/local /usr /usr/local/opt/gettext; do


configure: error: mcrypt.h not found. Please reinstall libmcrypt.
➜  php-7.0.13 brew install libmcrypt




提前于mac自带的调用:
sudo ln -s /usr/local/php7/bin/php /usr/local/bin/php


sudo ln -s /usr/local/php7/bin/pecl /usr/local/bin/pecl
sudo ln -s /usr/local/php7/bin/pear /usr/local/bin/pear
sudo ln -s /usr/local/php7/bin/php-cgi /usr/local/bin/php-cgi
sudo ln -s /usr/local/php7/bin/php-config /usr/local/bin/php-config
sudo ln -s /usr/local/php7/bin/phpize /usr/local/bin/phpize

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是CentOS 7安装PHP的两种方法: 1. 通过yum安装 ```shell # 安装epel-release仓库 yum install epel-release -y # 安装remi仓库 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y # 安装PHP7.4 yum install php74 -y # 安装常用扩展 yum install php74-php-mysqlnd php74-php-gd php74-php-xml php74-php-mbstring -y # 启动PHP-FPM服务 systemctl start php74-php-fpm.service # 设置开机自启动 systemctl enable php74-php-fpm.service ``` 2. 编译安装 ```shell # 安装编译PHP所需的依赖 yum install -y gcc gcc-c++ make autoconf libtool-ltdl-devel \ libxml2-devel libjpeg-devel libpng-devel freetype-devel \ openssl-devel curl-devel libxslt-devel libmcrypt-devel \ bzip2-devel readline-devel libedit-devel # 下载PHP源码包 wget https://www.php.net/distributions/php-7.4.30.tar.gz # 解压源码包 tar -zxvf php-7.4.30.tar.gz # 进入解压后的目录 cd php-7.4.30 # 配置编译参数 ./configure --prefix=/data/server/php \ --with-config-file-path=/data/server/php/lib \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype \ --with-jpeg \ --with-png \ --with-zlib \ --with-libxml-dir \ --enable-simplexml \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-soap \ --enable-zip \ --with-curl \ --enable-mbstring \ --with-openssl \ --with-mhash \ --enable-opcache \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-maintainer-zts \ --with-readline \ --with-libedit # 编译安装 make && make install # 复制php.ini文件 cp php.ini-production /data/server/php/lib/php.ini # 启动PHP-FPM服务 /data/server/php/sbin/php-fpm # 设置开机自启动 echo "/data/server/php/sbin/php-fpm" >> /etc/rc.local chmod +x /etc/rc.local ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值