php 编译 线程安全,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 解決辦法:安裝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
總結
以上是生活随笔為你收集整理的php 编译 线程安全,PHP7(zts 线程安全版)编译安装(支持多线程pthreads)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php下载的文件不是汉字,php实现支持
- 下一篇: php psr-2,「PSR 规范」PS