怎样安装Zend Guard Loader

2013年3月24日 | 分类: 【技术】

由于zend optimizer不支持php5.3,使用php5.3以上版本就要安装zend guard loader。

参考:https://amon.org/zend-optimizer

PHP 5.5:Zend Guard Loader for PHP 5.5
PHP 5.6:Zend Guard Loader for PHP 5.6
PHP 5.2 files encoded with Zend Guard 5.0 or Zend Guard 5.5 require Zend Optimizer as the runtime decoder.

【Atomic库安装】

参考:http://www.laozuo.org/1940.html

Atomic源支持Fedora,RHEL和CentOS的YUM包管理。

清单:http://www.atomicorp.com/channels/atomic/

需要先安装Atomic库,然后安装zend-guard-loader:

wget -q -O - http://www.atomicorp.com/installers/atomic | sh
yum install php-zend-guard-loader

安装完后在 /etc/yum.repos.d/ 目录会有一个 atomic.repo 文件。

【源码安装】

下载:http://www.zend.com/en/products/loader/downloads

参考:http://files.zend.com/help/Zend-Guard/content/installing_zend_guard_loader.htm
参考:http://www.cnblogs.com/qiandu/p/4201456
参考:https://serverpilot.io/community/articles/how-to-install-zend-guard-loader
参考:http://blog.chinaunix.net/uid-14735472-id-3764932
参考:http://jingyan.baidu.com/article/ceb9fb10dae0d98cad2ba005
参考:http://dedecms.com/knowledge/servers/linux-bsd/2012/0819/8491

wget http://downloads.zend.com/guard/7.0.0/zend-loader-php5.5-linux-x86_64_update1.tar.gz && tar zxvf zend-loader-php5.5-linux-x86_64_update1.tar.gz
cp -R zend-loader-php5.5-linux-x86_64/ /usr/local/zend/

编辑 php.ini ,在最后位置添加:

[Zend Guard]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

查证:

php -i | grep "Zend Guard Loader"

报错:

Failed loading /usr/local/php/lib/php/extensions/zend-loader-php5.5-linux-x86_64/ZendGuardLoader.so:  /usr/local/php/lib/php/extensions/zend-loader-php5.5-linux-x86_64/ZendGuardLoader.so: undefined symbol: executor_globals

参考:http://www.verydemo.com/demo_c101_i53243
参考:http://forums.zend.com/viewtopic.php?t=22958

参考:http://smilejay.com/2013/05/apache-mpm/
参考:http://www.aichengxu.com/view/934944

apache有两种运行模式:prefork模式;worker模式。区别请看:http://bbs.ywlm.net/thread-919-1-1
–with-mpm=worker 即worker模式,很多第三方模块不支持的
–with-mpm=prefork 重新编译apache就OK了。
如果用yum安装的,默认用的是prefork模式,这是为了兼容性。

参考:http://files.zend.com/help/Zend-Guard/content/installing_zend_guard_loader.htm
参考:http://www.phpfans.net/ask/question2/2455115949

参考:http://forums.zend.com/viewtopic.php?t=126063

Zend Guard Loader requires PHP NTS (non-thread-safe) and when loaded under Apache, use Prefork MPM.

参考:http://stackoverflow.com/questions/22201013/error-failed-loading-opcache-so-opcache-so-undefined-symbol-compiler-globals
参考:http://stackoverflow.com/questions/13883646/apache-prefork-vs-worker-mpm

You’re using Apache2 MPM. So PHP builds an ZTS (Zend Threaded System) build. See Apache Prefork vs Worker MPM for a discussion on this. With MPM PHP stores its compiler globals in a thread array. However, OPcache is looking for the non-threaded version of this structure compiler_globals.

IMO, if you are using a PHP, then using MPM is a mistake as (i) the PHP runs ~25-50% slower, (ii) many extension don’t work; (iii) OPcache isn’t properly tested with ZTS builds. Stick to a Prefork worker configuration, and rebuild.

以 –with-mpm=prefork 参数重新编译安装Apache2:

./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --with-mpm=prefork --with-crypto --enable-rewrite --enable-headers --enable-deflate --enable-socache-shmcb --enable-negotiation --enable-ssl --with-ssl=/usr/lib --enable-http2 --with-nghttp2=/usr/local/lib

查看当前apache中已经编译了的模块:

service httpd  -l

输出:

Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  prefork.c

由于MPM只能在编译时指定其中一种,所以列出的静态模块中MPM只有1个:

查看httpd加载的所有模块(包括静态编译的和动态共享的模块):

service httpd -t -D DUMP_MODULES

输出:

Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 dir_module (shared)
 alias_module (shared)
 cgid_module (shared)
 php5_module (shared)

查看 httpd.conf,有关于 mpm 模式的设置:

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

conf/extra/httpd-mpm.conf 的对应设置:

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of connections a server process serves
#                         before terminating
<IfModule mpm_prefork_module>
    StartServers             5
    MinSpareServers          5
    MaxSpareServers         10
    MaxRequestWorkers      250
    MaxConnectionsPerChild   0
</IfModule>

参考:https://smyl.es/how-to-fix-ioncubezendguard-undefined-symbol-executor_globals-after-upgrading-apache-and-php/
参考:http://stackoverflow.com/questions/17272439/how-to-enable-zts-on-php
参考:https://github.com/krakjoe/pthreads/issues/436

重新编译安装PHP
重新安装ZendOptimizer
在程序都重新编译安装完后,重启Apache,就可以了

输出:

with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
Zend Guard Loader
Zend Guard Loader => enabled

部署zend guard

实证未遂。

参考:http://files.zend.com/help/Zend-Guard/content/install.htm
参考:http://static.zend.com/topics/Zend-Guard-Release-Notes-v5-5.txt

下载:http://www.zend.com/en/products/guard/downloads

http://downloads.zend.com/guard/7.0.0/ZendGuard-7.0.0-linux.gtk.x86_64.tar.gz
http://downloads.zend.com/guard/6.0.0/ZendGuard-6_0_0-linux.tar.gz
http://downloads.zend.com/guard/5.5.0/ZendGuard-5_5_0.tar.gz

wget http://downloads.zend.com/guard/5.5.0/ZendGuard-5_5_0.tar.gz && tar zxvf ZendGuard-5_5_0.tar.gz && ./ZendGuard-5_5_0.bin