前段时间遇到一个项目是用php 5.2加zend加密模块来写的项目,但自己机器最低的php版本也是5.3,咋办呢?
在brew上搜索了半天,也在github上找了一圈也没找到,看到brew上的最低版本也是php5.3。
看来只能自己手动编译了~
在网上搜索了一些文章依次按照步骤安装:
1、安装必要扩展
1 |
brew install libxml2 --with-python libtool openssl |
其它的就不描述了
2、下载相应的源码包
1 2 3 |
wget http://soft.7dot.com/soft/php-5.2.17.tar.gz wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz wget https://raw.github.com/laruence/laruence.github.com/master/php-5.2-max-input-vars/php-5.2.17-max-input-vars.patch |
1 2 3 4 5 6 7 8 |
tar zxvf php-5.2.17.tar.gz # 打补丁 gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 cd php-5.2.17 # 打补丁 patch -p1 < ../php-5.2.17-max-input-vars.patch sed -i "s/\!png_check_sig (sig, 8)/png_sig_cmp (sig, 0, 8)/" ext/gd/libgd/gd_png.c cd php-5.2.17 |
3、执行安装脚本
1 |
./configure --prefix=/usr/local/opt/php52 --with-config-file-path=/usr/local/etc/php/5.2 --with-mysql=/usr/local/opt/mysql --with-mysqli=/usr/local/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-libxml-dir=/usr --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2k/ |
4、修改部分文件
搜索 ext/dom/node.c
文件
将
1 2 3 4 5 6 7 8 9 |
RETVAL_FALSE; } else { if (mode == 0) { ret = buf->buffer->use; if (ret > 0) { RETVAL_STRINGL((char *) buf->buffer->content, ret, 1); } else { RETVAL_EMPTY_STRING(); } |
修改为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
RETVAL_FALSE; } else { if (mode == 0) { #ifdef LIBXML2_NEW_BUFFER ret = xmlOutputBufferGetSize(buf); #else ret = buf->buffer->use; #endif if (ret > 0) { #ifdef LIBXML2_NEW_BUFFER RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1); #else RETVAL_STRINGL((char *) buf->buffer->content, ret, 1); #endif } else { RETVAL_EMPTY_STRING(); } |
搜索 ext/dom/documenttype.c
文件
将
1 2 3 4 5 6 7 8 9 |
if (buff != NULL) { xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL); xmlOutputBufferFlush(buff); ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1); (void)xmlOutputBufferClose(buff); return SUCCESS; } |
修改为
1 2 3 4 5 6 7 8 9 10 11 12 13 |
if (buff != NULL) { xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL); xmlOutputBufferFlush(buff); #ifdef LIBXML2_NEW_BUFFER ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff), 1); #else ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1); #endif (void)xmlOutputBufferClose(buff); return SUCCESS; } |
搜索 ext/simplexml/simplexml.c
文件
将
1 2 3 4 5 6 7 8 |
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding); xmlOutputBufferFlush(outbuf); RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1); xmlOutputBufferClose(outbuf); } } else { |
修改为
1 2 3 4 5 6 7 8 9 10 11 |
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding); xmlOutputBufferFlush(outbuf); #ifdef LIBXML2_NEW_BUFFER RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), xmlOutputBufferGetSize(outbuf), 1); #else RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1); #endif xmlOutputBufferClose(outbuf); } } else { |
5、执行make
1 2 3 |
make ZEND_EXTRA_LIBS='-liconv' make install cp php.ini-dist /usr/local/etc/php/5.2/php.ini |
注意编译过程中指定mysql,openssl目录,要不然会报错
6、编译安装PHP5扩展模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
wget http://pecl.php.net/get/memcache-2.2.6.tgz tar zxvf memcache-2.2.6.tgz cd memcache-2.2.6/ /usr/local/opt/php52/bin/phpize ./configure --with-php-config=/usr/local/opt/php52/bin/php-config make && make install cd .. wget http://zpanel.xiugan.com/centos/package/eaccelerator-0.9.6.1.tar.bz2 tar jxvf eaccelerator-0.9.6.1.tar.bz2 cd eaccelerator-0.9.6.1/ /usr/local/opt/php52/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/opt/php52/bin/php-config --without-eaccelerator-use-inode make && make install cd .. wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz tar zxvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL-1.0.2 /usr/local/opt/php52/bin/phpize ./configure --with-php-config=/usr/local/opt/php52/bin/php-config --with-pdo-mysql=/usr/local/opt/mysql make && make install cd .. wget http://pecl.php.net/get/imagick-3.0.1.tgz tar zxvf imagick-3.0.1.tgz cd imagick-3.0.1 /usr/local/opt/php52/bin/phpize ./configure --with-php-config=/usr/local/opt/php52/bin/php-config --with-imagick=/usr/local/opt/imagemagick@6 make && make install cd .. |
注意用brew安装 brew install imagemagick@6 编译 imagick时需要,添加软链
1 |
ln -s /usr/local/opt/imagemagick\@6/include/ImageMagick-6 /usr/local/opt/imagemagick\@6/include/ImageMagick |
不然安装imagick时会报Cannot locate header file MagickWand.h
的错误
7、修改配置文件
命令行执行
1 2 3 4 5 6 7 8 |
sed -i "s/output_buffering = Off/output_buffering = On/" /usr/local/etc/php/5.2/php.ini sed -i "s/extension_dir =/; extension_dir =/" /usr/local/etc/php/5.2/php.ini sed -i "s/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/" /usr/local/etc/php/5.2/php.ini sed -i 's%;open_basedir =%open_basedir ="/tmp/:/usr/local/opt/tengine/html/"%' /usr/local/etc/php/5.2/php.ini sed -i "s/disable_functions =/disable_functions = popen,pentl_exec,passthru,exec,system,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,show_source,escapeshellcmd,escapeshellarg,curl_exec,curl_multi_exec,parse_ini_file,assert/" /usr/local/etc/php/5.2/php.ini sed -i "s/expose_php = On/expose_php = Off/" /usr/local/etc/php/5.2/php.ini sed -i "s/display_errors = On/display_errors = Off/" /usr/local/etc/php/5.2/php.ini sed -i "s/log_errors = Off/log_errors = On/" /usr/local/etc/php/5.2/php.ini |
在php.ini文件尾添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
extension_dir = "/usr/local/opt/php52/lib/php/extensions/no-debug-non-zts-20060613/" extension = "memcache.so" extension = "pdo_mysql.so" extension = "imagick.so" [eaccelerator] zend_extension="/usr/local/opt/php52/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="1" eaccelerator.cache_dir="/var/data/cache/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="3600" eaccelerator.shm_prune_period="3600" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" eaccelerator.keys = "disk_only" eaccelerator.sessions = "disk_only" eaccelerator.content = "disk_only |
8、创建eAccelerator缓存目录
1 |
mkdir -p /var/data/cache/eaccelerator |