Update, PHP-4.4.4! Update, eAccelerator! Update, WordPress 2.0.6!

[photopress:Night_of_Miracles_by_Licheus.jpg,full,pp_image]

前几天在robinz那看到了在Dreamhost上安装eAccelerator的教程,听说eAccelerator要比zend快多了,手就有点痒,这几天都在尝试编译安装PHP-4.4.4,但已经出错了三次,大都是因为脚本的问题,准备第四次的时候竟然一不小心rm -rf php *差点把所有东西都删了,幸好还有较早前的备份才恢复过来,今天就把Wordpress升到2.0.6,趁还有时间顺便也把页面的css调整了一下,加了两张背景。

实际动手才发觉跟想象的也差太远了,安装PHP4就是因为参数和网数的问题令成功几率大大降低,而且在网上的那些脚本多数都不太完全对的,需要改动的地方也不少。就PHP4的编译小弟也积累了些经验, 刚开始我只按照robinz的方法装的,但是因为php4已经出到4.4.4了,而iMap也升级到2006了,2004g的下载地址也已经失效了,还有一好几个文件镜像都失效,后来只好参照Dreamhost官方提供的脚本重新编译,而又因为Dreamhost的脚本写的比较优美,所以我最后还是以它为基础按照robinz的参数重新安装。在这里有几点要注意的,Dreamhost提供的脚本是默认没有打开FastCGI参数的,而robinz上面又有几个变量稍微不同,还有编译的时候最好把脚本放到$HOME目录执行,这样才不会产生多余的php链接。

下面是我修改过的脚本

#!/bin/bash

# Abort on any errors
set -e

# The domain in which to install the PHP CGI script.
export DOMAIN=”freemagi.com”

# Update version information here.
PHP=”php-4.4.4″
LIBICONV=”libiconv-1.10″
LIBMCRYPT=”libmcrypt-2.5.7″
LIBXML2=”libxml2-2.6.23″
LIBXSLT=”libxslt-1.1.15″
MHASH=”mhash-0.9.4″; MHASH_TAR=”${MHASH}a” # Pests!
ZLIB=”zlib-1.2.3″
CURL=”curl-7.15.2″
LIBIDN=”libidn-0.6.2″
FREETYPE=”freetype-2.1.10″
IMAP=”imap-2004g”
# Set DISTDIR to somewhere persistent if you plan to muck around with this
# script and run it several times! It is where distributions are downloaded.
DISTDIR=${HOME}/dist

# Where do you want all this stuff built? Using a local filesystem is best.
# ***Don’t pick a directory that already exists!*** We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source

# And where should it be installed? A versioned directory eases upgrades!
INSTALLDIR=${HOME}/${PHP}

# A simple name link eases use
ln -s ${INSTALLDIR} php
# What PHP features do you want enabled?
PHPFEATURES=”–prefix=${INSTALLDIR} \
–enable-force-cgi-redirect \
–enable-gd-native-ttf \
–enable-ftp \
–enable-sockets \
–enable-wddx \
–enable-sqlite-utf8 \
–enable-calendar \
–enable-mbstring \
–enable-mbregex \
–enable-soap \
–enable-fastcgi \
–enable-exif \
–with-config-file-path=${INSTALLDIR}/etc/php4 \
–with-xml \
–with-libxml-dir=${INSTALLDIR} \
–with-freetype-dir=${INSTALLDIR} \
–with-xsl=${INSTALLDIR} \
–with-openssl=/usr \
–with-mhash=${INSTALLDIR} \
–with-mcrypt=${INSTALLDIR} \
–with-zlib-dir=${INSTALLDIR} \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-gd \
–with-mysql=/usr –with-mysqli \
–with-curl=${INSTALLDIR} \
–with-iconv=${INSTALLDIR} \
–with-imap=${INSTALLDIR}
–with-imap-ssl=/usr \
–with-gettext \
–without-pear”

# —- end of user-editable bits. Hopefully! —-

# Push the install dir’s bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH

#setup directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}

# Get all the required packages
wget -c http://us3.php.net/distributions/${PHP}.tar.gz
wget -c http://ftp.gnu.org/pub/gnu/libiconv/${LIBICONV}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
wget -c http://xmlsoft.org/sources/xml/${LIBXML2}.tar.gz
wget -c http://xmlsoft.org/sources/xml/${LIBXSLT}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mhash/${MHASH_TAR}.tar.gz
wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://curl.haxx.se/download/${CURL}.tar.gz
wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
wget -c ftp://ftp.cac.washington.edu/imap/old/${IMAP}.tar.Z

cd ${SRCDIR}
# Unpack them all
tar xzf ${DISTDIR}/${PHP}.tar.gz
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz
tar xzf ${DISTDIR}/${MHASH_TAR}.tar.gz
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
tar xzf ${DISTDIR}/${CURL}.tar.gz
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
tar xzf ${DISTDIR}/${FREETYPE}.tar.gz
uncompress -cd ${DISTDIR}/${IMAP}.tar.Z |tar x

# Build them in the required order to satisfy dependencies.

#libiconv
cd ${SRCDIR}/${LIBICONV}
./configure –enable-extra-encodings –prefix=${INSTALLDIR}
make
make install

#libxml2
cd ${SRCDIR}/${LIBXML2}
./configure –with-iconv=${INSTALLDIR} –prefix=${INSTALLDIR}
make
make install

#libxslt
cd ${SRCDIR}/${LIBXSLT}
./configure –with-libxml-prefix=${INSTALLDIR} –prefix=${INSTALLDIR}
make
make install

#zlib
cd ${SRCDIR}/${ZLIB}
./configure –shared –prefix=${INSTALLDIR}
make
make install

#libmcrypt
cd ${SRCDIR}/${LIBMCRYPT}
./configure –disable-posix-threads –prefix=${INSTALLDIR}
make
make install

#mhash
cd ${SRCDIR}/${MHASH}
./configure –prefix=${INSTALLDIR}
make
make install
# FIXME: For some reason, mincludes.h isn’t copied across
cp ${SRCDIR}/${MHASH}/include/mutils/mincludes.h ${INSTALLDIR}/include/mutils

#libidn
cd ${SRCDIR}/${LIBIDN}
./configure –with-iconv-prefix=${INSTALLDIR} –prefix=${INSTALLDIR}
make
make install

#cURL
cd ${SRCDIR}/${CURL}
./configure –with-ssl=${INSTALLDIR} –with-zlib=${INSTALLDIR} \
–with-libidn=${INSTALLDIR} –enable-ipv6 –enable-cookies \
–enable-crypto-auth –prefix=${INSTALLDIR}
make
make install

#freetype
cd ${SRCDIR}/${FREETYPE}
./configure –prefix=${INSTALLDIR}
make
make install

# imap
cd ${SRCDIR}/${IMAP}
make ldb
# Install targets are for wusses!
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include

#PHP 4
cd ${SRCDIR}/${PHP}
./configure ${PHPFEATURES}
make
make install

#copy config file
mkdir -p ${INSTALLDIR}/etc/php4
cp ${SRCDIR}/${PHP}/php.ini-dist ${INSTALLDIR}/etc/php4/php.ini

#copy PHP CGI
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
echo ———- INSTALL COMPLETE! ———-

Download: instphp4.sh

运行

chmod +x instphp4.sh
./instphp4.sh


然后就到安装我们这次的主角eAcceleartor,开始安装前还要几步准备工作,先把autoconf和automake装上,可以参考robinz的做法,而我是选择安装在~/local,因个人情况不同。安装autoconf

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.59.tar.bz2
tar -xjf autoconf-2.59.tar.bz2
cd autoconf-2.59
./configure -prefix=YOUR PATH
make
make install

安装automake

wget http://ftp.gnu.org/gnu/automake/automake-1.9.6.tar.bz2
tar -xjf automake-1.9.6.tar.bz2
cd automake-1.9.6
./configure -prefix=YOUR PATH
make
make install

然后我们来看看eAccelerator的软件环境需求:
apache 1.3, apache 2.0 (prefork), mod_php4/5
我们的Dreamhost都能够支持,好了,下面到请主角出场:

安装eAccelerator(下面的地址如果不通的话最好自己到eAccelerator的PojectPage找合适的镜像)

wget http://voxel.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2
tar -xjf eaccelerator-0.9.5.tar.bz2
cd eaccelerator-0.9.5
export PATH=$PATH:YOUR PATH/bin #这里的是指你安装autoconf的目录,譬如我的是$HOME/local/bin
export PHP_PREFIX=YOUR PHP PATH #这里是你的安装php的位置,就是$HOME/php,但有一个小细节要注意的,在robinz的文里是写export PHP_PREFIX= YOUR PHP PATH/bin的,其实如果这样写的话,configure是不会成功的
$PHP_PREFIX/bin/phpize
./configure -prefix=YOUR PATH –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config
make
make install #最好还是make install一下,不make install会有la文件
mv YOUR PHP PATH/lib/php/extensions/no-debug-non-zts-一行数字/eaccelerator.so YOUR PHP PATH/lib/php/extensions/
rm -r YOUR PHP PATH/lib/php/extensions/no-debug-non-zts-一行数字/


上面结束以后还不用急,还要设置一下php.ini
cp /etc/php/cgi/php.ini “$HOME/[your website directory]/cgi-bin/”
然后再改一下这个复制过来的文件把文件末的以zend开头的两行都删掉
把下面的这些文字加到文件末尾

[eAccelerator]
zend_extension="/home/YOUR PHP PATH/lib/php/extensions/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/home/YOUR HOME/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

[Zend]
zend_extension=”/usr/local/dh/apache/template/phpext/ZendExtensionManager.so”
zend_extension=”/usr/local/dh/apache/template/phpext/zend_optimizer4/ZendOptimizer.so”
zend_optimizer.optimization_level=1023

然后再运行

mkdir -p ~/tmp/eaccelerator
chmod 777 ~/tmp/eaccelerator

最后,别忘了在你的.htaccess文件里加上

AddHandler phpFour .php
Action phpFour /cgi-bin/php.cgi

再下一个iProber 探针,看看PHPINFO就可以看到

This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with eAccelerator v0.9.5, Copyright (c) 2004-2006 eAccelerator, by eAccelerator with Zend Extension Manager v1.0.9, Copyright (c) 2003-2006, by Zend Technologies with Zend Optimizer v2.6.2, Copyright (c) 1998-2006, by Zend Technologies



ENJOY!
最后再附送两个备份脚本,分别是备份MySQL和文件到别的ftp上的脚本,写得比较草,不要笑小弟[发现几个错误,请把原asc改成gpg]

先是数据库备份脚本
#ftp Info
host=HOST #ftp host
UserName=USER #ftp user name
Passwd=PASSWD #fto user password

#MySQL Info
SQL_host=DB_HOST #MySQL host
SQL_User=DB_USER #MySQL UserName
SQL_Passwd=DB_PASSWD #User Password
SQL_db=DB_NAME #database name

backup_path=/home/YOUR TMP PATH #set saved backup path
file=$SQL_db-$(date +%Y%m%d).tar.gz
MySQL_path=/usr/bin #set the mysql database bin path

cd $backup_path
#export database
$MySQL_path/mysqldump -h $SQL_host -u$SQL_User -p$SQL_Passwd –databases $SQL_db>$SQL_db.dump

sleep 5s
#file tar
tar -czf $backup_path/$file $SQL_db.dump
gpg -e -r GPGID $file #有关gpg加解密请GOOGLE一下

cd $backup_path

#file ftp
ftp -i -n <<!
open $host
user $UserName $Passwd
cd /dbbak #请事先在你的备份用FTP上建立此目录
put $file.gpg
bye
!

sleep 10s
rm -rf $backup_path/$file
rm -rf $backup_path/$SQL_db.dump
rm -rf $backup_path/$file.gpg


然后是文件备份的
WEBFILE=webdir-$(date +%Y%m%d).tar.gz
cd $HOME

sleep 1s
tar -czf $HOME/YOUR TMP PATH/webdir-$(date +%Y%m%d).tar.gz $HOME/YOUR PATH

sleep 10s
cd $HOME/YOUR TMP PATH
gpg -e -r YOUR GPG ID $WEBFILE

sleep 15s
ftp -i -n <<!
open YOUR FTP HOST
user USERNAME PASSWD
cd webbak #这个也是要事先建好
put $WEBFILE.gpg
bye
!

sleep 5s
rm -rf $HOME/YOUR TMP PATH/$WEBFILE.gpg
rm -rf $HOME/YOUR TMP PATH/$WEBFILE


Enjoy!

4 thoughts on “Update, PHP-4.4.4! Update, eAccelerator! Update, WordPress 2.0.6!

Share Your Thought