正在加载……
Dreamhost定制安装PHP
| |
Posted in Life on 2008/01/21 / 引用(0)
对于一般的PHP应用,Dreamhost控制面板提供php4、php5一键切换,非常方便。如果想定制php,就可以参考下我这里的经历了。

Dreamhost wiki中介绍了定制安装php的方法,本来我就是按照第一种方法安装的,但是总是提示错误。还好,DHwiki中提到了第二种方法(以下都在SSH中进行):

1.创建php5-install-prep.sh

vim php5-install-prep.sh


代码如下:
#!/bin/sh

# Version 0.6, 2007-12-16
#
# - Updated 2007-12-16 by AskApache (www.askapache.com)
#   - Implemented functions to fetch the URI and decompress it
#   - Added a couple more error-checks
#   - Replaced wget with cURL
#   - Added more to help keep it from getting killed
#   - Updated to php-5.2.3, curl-7.17.1, freetype-2.3.5
# - Updated 2007-01-15 by Charles Wiltgen (charles@wiltgen.net)
#   - Make "nicer" to help keep it from getting killed by DreamHost
#   - Make less verbose to keep signal-to-noise level high
# - Updated 2006-12-25 by Carl McDade (hiveminds.co.uk)
#   - Allow memory limit and freetype

# Abort on any errors
set -e

# The domain in which to install the PHP CGI script.
export DOMAIN="[color=#FF0000]此处填写域名目录[/color]"

# Where do you want all this stuff built? I'd recommend picking a local filesystem.
# ***Don't pick a directory that already exists!***
SRCDIR=${HOME}/source

# And where should it be installed?
INSTALLDIR=${HOME}/php5

# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist


# Update version information here。“PHP5=”处填写你想要的版本。
PHP5="[color=#FF0000]php-5.2.4[/color]"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.27"
LIBXSLT="libxslt-1.1.18"
MHASH="mhash-0.9.7.1"
ZLIB="zlib-1.2.3"
CURL="curl-7.17.1"
LIBIDN="libidn-0.6.8"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g"
FREETYPE="freetype-2.3.5"

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


function aa_unpack () {
  # compressed, tar and gzip files to DISTDIR
  if [ -f $DISTDIR/$1* ] ; then
    echo Extracting "$1";
    zcat ${DISTDIR}/$1* | tar -xvf - &>/dev/null;
    echo Done.;  echo; wait
  fi
}


function aa_grab () {
  #saves file to SRCDIR
    echo `basename $1`
  curl -L --retry 20 --max-time 1800 --retry-delay 30 -# -f --max-redirs 4 --remote-name "$1"
}


echo
echo --------------------------------------------------
echo --   Run this script before php5-install.sh     --
echo --------------------------------------------------
echo
echo - Downloads and unpacks all prerequisite packages
echo - **SRCDIR and DISTDIR will be deleted**
echo
read -p  "        (Press any key to continue)" temp;
echo;echo

# cleanup to remove source and dist directories if present
if [ -d "$SRCDIR" ] || [ -d "$DISTDIR" ];then
  echo
  echo --- Cleaning up any previous attempts ---
  rm -rf $SRCDIR $DISTDIR &>/dev/null
  echo Done.
  echo
  wait
fi


#setup directories
mkdir -p ${SRCDIR} ${INSTALLDIR} ${DISTDIR} &>/dev/null

# Get all the required packages
echo;echo
echo --- Downloading all required packages ---
echo

cd ${DISTDIR}
aa_grab http://us.php.net/distributions/${PHP5}.tar.gz
aa_grab http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
aa_grab http://umn.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
aa_grab ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
aa_grab ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
aa_grab http://umn.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
aa_grab http://www.zlib.net/${ZLIB}.tar.gz
aa_grab http://curl.haxx.se/download/${CURL}.tar.gz
aa_grab http://easynews.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
aa_grab ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
aa_grab ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z
wait
echo Done.


# Extract the files from the required packages.
echo;echo;echo
echo --- Unpacking downloaded archives. This process may take several minutes! ---
echo

cd ${SRCDIR}
aa_unpack ${PHP5}
aa_unpack ${LIBICONV}
aa_unpack ${LIBMCRYPT}
aa_unpack ${LIBXML2}
aa_unpack ${LIBXSLT}
aa_unpack ${MHASH}
aa_unpack ${ZLIB}
aa_unpack ${CURL}
aa_unpack ${LIBIDN}
aa_unpack ${CCLIENT}
aa_unpack ${FREETYPE}
wait

echo --------------------------------------------------
echo -- Done downloading and unpacking prerequisites --
echo --------------------------------------------------

exit 0;


ESC  :wq 保存退出

2.给这个文件可执行权限:

chmod +x php5-install-prep.sh


3.执行文件

./php5-install-prep.sh


4.创建php5-install.sh 文件

#!/bin/sh

echo php5-install.sh
echo - This script compiles and installs PHP 5 and all prerequisites
echo - Run php5-install-prep.sh before running this script
echo
read -p  "(Press any key to continue)" temp;
echo

# Version 0.6, 2007-12-20
#
# - Updated 2007-01-15 by Charles Wiltgen (charles@wiltgen.net)
#   - Make "nicer" to help keep it from getting killed by DreamHost
#   - Make less verbose to keep signal-to-noise level high
# - Updated 2006-12-25 by Carl McDade (hiveminds.co.uk)
#   - Allow memory limit and freetype
# - Updated 2007-12-20 by David Szpunar (infotech.lakeviewchurch.org)
#   - Update versions of freetype, curl, php5 to match php5-install-prep.sh

# - updated 2008-01-16 by osha (osha@iqresearch.com)
#   - fixed some typos and made more explicit what the domain variable is

# Abort on any errors
set -e

##################################
# User-editable settings (start) #
##################################

# The domain in which to install the PHP CGI script
# this is the name of the folder that your domain reads files from
# (no "www" unless it is in the folder name)
export DOMAIN="[color=#FF0000]your-domain-here.com[/color]"

# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***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?
INSTALLDIR=${HOME}/php5

# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist

# Update version information here. PHP5处为php版本。
PHP5="[color=#FF0000]php-5.2.4[/color]"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.27"
LIBXSLT="libxslt-1.1.18"
MHASH="mhash-0.9.7.1"
ZLIB="zlib-1.2.3"
CURL="curl-7.17.1"
LIBIDN="libidn-0.6.8"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g" # Another pest!
FREETYPE="freetype-2.3.5"

# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
  --with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
  --enable-fastcgi \
  --enable-force-cgi-redirect \
  --with-xml \
  --with-libxml-dir=${INSTALLDIR} \
  --with-freetype-dir=${INSTALLDIR} \
  --enable-soap \
  --with-openssl=/usr \
  --with-mhash=${INSTALLDIR} \
  --with-mcrypt=${INSTALLDIR} \
  --with-zlib-dir=${INSTALLDIR} \
  --with-jpeg-dir=/usr \
  --with-png-dir=/usr \
  --with-gd \
  --enable-gd-native-ttf \
  --enable-memory-limit
  --enable-ftp \
  --enable-exif \
  --enable-sockets \
  --enable-wddx \
  --with-iconv=${INSTALLDIR} \
  --enable-sqlite-utf8 \
  --enable-calendar \
  --with-curl=${INSTALLDIR} \
  --enable-mbstring \
  --enable-mbregex \
  --with-mysql=/usr \
  --with-mysqli \
  --without-pear \
  --with-gettext \
  --with-imap=${INSTALLDIR} \
  --with-imap-ssl=/usr"

################################
# User-editable settings (end) #
################################

echo ------------------------------------------------------
echo -- Compiling and installing PHP 5 and prerequisites --
echo ------------------------------------------------------

# Pre-prep cleanup
rm -rf $INSTALLDIR

# Build packages in the required order to satisfy dependencies.

#
# libiconv
#

echo
echo --- Building libiconv
echo
cd ${SRCDIR}/${LIBICONV}
echo "    Configuring..."
./configure --enable-extra-encodings --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# libxml2
#

echo
echo --- Building libxml2
echo
cd ${SRCDIR}/${LIBXML2}
echo "    Configuring..."
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# libxslt
#

echo
echo --- Building libxslt
echo
cd ${SRCDIR}/${LIBXSLT}
echo "    Configuring..."
./configure --prefix=${INSTALLDIR} \
  --with-libxml-prefix=${INSTALLDIR} \
  --with-libxml-include-prefix=${INSTALLDIR}/include/ \
  --with-libxml-libs-prefix=${INSTALLDIR}/lib/ \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# zlib
#

echo
echo --- Building: zlib
echo
cd ${SRCDIR}/${ZLIB}
echo "    Configuring..."
./configure --shared --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# libmcrypt
#

echo
echo --- Building: libmcrypt
echo
cd ${SRCDIR}/${LIBMCRYPT}
echo "    Configuring..."
./configure --disable-posix-threads --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#libmcrypt lltdl issue!!
cd  ${SRCDIR}/${LIBMCRYPT}/libltdl
echo "    Configuring..."
./configure --prefix=${INSTALLDIR} --enable-ltdl-install \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# mhash
#

echo
echo --- Building: mhash
echo
cd ${SRCDIR}/${MHASH}
echo "    Configuring..."
./configure --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# freetype
#

echo
echo --- Building: freetype
echo
cd ${SRCDIR}/${FREETYPE}
echo "    Configuring..."
./configure --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# libidn
#

echo
echo --- Building: libidn
echo
cd ${SRCDIR}/${LIBIDN}
echo "    Configuring..."
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# cURL
#

echo
echo --- Building: cURL
echo
cd ${SRCDIR}/${CURL}
echo "    Configuring..."
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
  --with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
  --enable-crypto-auth --prefix=${INSTALLDIR} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Done!"

#
# c-client
#

echo
echo --- Building: c-client
echo
cd ${SRCDIR}/${CCLIENT_DIR}
echo "    Making..."
make ldb  > /dev/null 2>&1
echo "    Installing..."
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include
echo "    Done!"

#
# PHP 5
#

echo
echo --- Building PHP 5 ---
echo
cd ${SRCDIR}/${PHP5}
echo "    Configuring..."
./configure ${PHPFEATURES} \
  > /dev/null 2>&1
echo "    Making..."
nice -n 19 make > /dev/null 2>&1
echo "    Installing..."
make install > /dev/null 2>&1
echo "    Copying configuration file (PHP.INI)"
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
echo "    Copying PHP CGI"
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin

# uncomment the line below for newer versions of php5 (5.23 and higher)
# cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi

echo
echo --- Cleaning up
echo

rm -rf $SRCDIR $DISTDIR

echo ---------------------------------------
echo ---------- INSTALL COMPLETE! ----------
echo ---------------------------------------

# Finally, you need to add this to your site's .htaccess file to use
# the version of PHP that you've just compiled:
#
# AddHandler phpFive .php
# Action phpFive /cgi-bin/php.cgi



注意修改目录和php版本。如果打算安装php5.2.3或者更高版本的PHP,需要在这个脚本里面找到:
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi


把这一行替换成:

cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi


5.设置可执行权限

chmod +x php5-install.sh

然后运行
./php5-install.sh


6.脚本执行完毕之后,php5算是安装完成,这个时候你要使用.htaccess来使用这个PHP5,在”your.domain.com”这个目录下新建一个.htaccess文件,内容为:

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


自此,你的这个域名使用的就是自己安装的PHP版本,这个时候php.ini位于
/$home/username/php5/etc/php5/Domainname/

可以使用任意文本编辑器编辑这个文件来满足自己的要求。
6.你也可以让其他域名使用这个PHP版本,使用SSH进入你想使用这个PHP版本的目录下,输入:

ln -s /home/USERNAME/DOMAIN_NAME/cgi-bin /home/USERNAME/SUB.DOMAIN_NAME/cgi-bin


简单的幸福
http://www.lovewait.net
Google G1解锁、黑莓解锁、三星解锁、摩托罗拉解锁,任意GSM网络手机解锁 联系QQ:621815789 淘宝旺旺: 小鱼王子 淘宝店铺:http://shop33625588.taobao.com
This entry comes from 本站原创 and has been read for 1126 times.It is tagged with , , .
发表评论

昵称

网址

电邮

OpenID登入 高级选项 表情