1. 安装依赖的编译工具
apt-get update 更新源

apt-get install gcc make gdb autoconf g++ libncurses5-dev curl libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev libfreetype6-dev libsasl2-dev libperl-dev libtool libxml2-dev libtidy-dev libpcre3 libpcre3-dev libmcrypt-dev libmhash-dev install build-essential bison chrpath debhelper flex freetds-dev libapr1-dev libbz2-dev libc-client-dev libexpat1-dev libfreetype6-dev libgcrypt11-dev libgd2-xpm-dev libjpeg62-dev libkrb5-dev libldap2-dev libmcrypt-dev libmhash-dev libmysqlclient15-dev libncurses5-dev libpam0g-dev libpcre3-dev libpng12-dev libpq-dev libpspell-dev librecode-dev libsnmp9-dev libsqlite0-dev libt1-dev libtidy-dev libwrap0-dev libxmltok1-dev libxml2-dev libxslt1-dev re2c unixodbc-dev

apt-get install build-essential

2. 安装所需工具
libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar -zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure –prefix=/usr/local/libiconv
make && make install

libxml2
wget http://xmlsoft.org/sources/libxml2-2.7.3.tar.gz
tar -zxvf libxml2-2.7.3.tar.gz
cd libxml2-2.7.3
./configure –prefix=/usr/local/libxml2
make && make install

curl
wget http://curl.haxx.se/download/curl-7.19.6.tar.gz
tar -zxvf curl-7.19.6.tar.gz
cd curl-7.19.6
./configure –prefix=/usr/local/curl

openssl
wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz
tar -zxvf openssl-0.9.8k.tar.gz
cd openssl-0.9.8k
./config
make && make install

zlib
wget http://google-desktop-for-linux-mirror.googlecode.com/files/zlib-1.2.3.tar.gz
tar -zxvf zlib-1.2.3.tar.gz
cd zlib/1.2.3
./configure –prefix=/usr/local/zlib

3.安装mysql
groupadd mysql
useradd -g mysql mysql

wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.41.tar.gz
tar -zxvf mysql-5.1.41.tar.gz
cd mysql-5.1.41
./configure –prefix=/usr/local/mysql/ –without-debug –without-bench –enable-thread-safe-client –enable-assembler –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-charset=latin1 –with-extra-charset=utf8,gbk –with-innodb –with-cvs-storage-engine –with-federated-storage-engine –with-mysqld-user=mysql –without-embedded-server –with-server-suffix=-community –with-unix-socket-path=/usr/local/mysql/sock/mysql.sock

make && make install

cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .

mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
export PATH=/usr/local/mysql/bin/:$PATH
bin/mysql_install_db –user=mysql

chown -R root .
chown -R mysql var
chown -R mysql var/.
chown -R mysql var/mysql/.
chgrp -R mysql .
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

chmod 777 /etc/init.d/mysql
bin/mysqld_safe –user=mysql &

4. 安装Nginx

wget http://nginx.org/download/nginx-0.7.67.tar.gz

tar -zxvf nginx-0.7.67.tar.gz

cd /sof
cd nginx-0.7.67
./configure –sbin-path=/usr/local/sbin –with-http_ssl_module –with-http_stub_status_module
make && make install

创建启动文件

vi /etc/init.d/nginx

#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-De.ion: starts the nginx web server
# De.ion: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case “$1″ in
start)
echo -n “Starting $DESC: ”
start-stop-daemon –start –quiet –pidfile /usr/local/nginx/logs/nginx.pid \
–exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
stop)
echo -n “Stopping $DESC: ”
start-stop-daemon –stop –quiet –pidfile /usr/local/nginx/logs/nginx.pid \
–exec $DAEMON
echo “$NAME.”
;;
restart|force-reload)
echo -n “Restarting $DESC: ”
start-stop-daemon –stop –quiet –pidfile \
/usr/local/nginx/logs/nginx.pid –exec $DAEMON
sleep 1
start-stop-daemon –start –quiet –pidfile \
/usr/local/nginx/logs/nginx.pid –exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
reload)
echo -n “Reloading $DESC configuration: ”
start-stop-daemon –stop –signal HUP –quiet –pidfile /usr/local/nginx/logs/nginx.pid \
–exec $DAEMON
echo “$NAME.”
;;
*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|force-reload}” >&2
exit 1
;;
esac
exit 0

添加脚本到系统默认运行级别
/usr/sbin/update-rc.d -f nginx defaults

由于nginx是安装在/usr/local/,可以链接到我们常用的/etc/下
ln -s /usr/local/nginx /etc/nginx

5. 安装PHP所需工具
libtool
wget http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz
tar zxvf libtool-2.2.6a.tar.gz
cd libtool-2.2.6
./configure –prefix=/usr/local/libtool
make && make install
cp /usr/local/libtool/share/libtool/config/config.sub /usr/share/libtool/config.sub
cp /usr/local/libtool/share/libtool/config/config.guess /usr/share/libtool/config.guess

jpegsrc
wget ftp://ftp.scw.net.br/pub/slamd64/slamd64-12.2/source/l/libjpeg/jpegsrc.v6b.tar.gz
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
mkdir /usr/local/jpeg
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/include
mkdir /usr/local/jpeg/man
mkdir /usr/local/jpeg/man/man1
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure –prefix=/usr/local/jpeg –enable-shared –enable-static
make && make install

libpng
wget http://prdownloads.sourceforge.net/libpng/libpng-1.2.8-config.tar.gz?download
tar zxvf libpng-1.2.8-config.tar.gz
cd libpng-1.2.8-config
./configure –prefix=/usr/local/png
make && make install

freetype
wget http://jaist.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.9.tar.gz
tar zxvf freetype-2.3.9.tar.gz
cd freetype-2.3.9
./configure –prefix=/usr/local/freetype
make && make install

gd
wget http://www.libgd.org/releases/oldreleases/gd-2.0.34.tar.gz
tar zxvf gd-2.0.34.tar.gz
cd gd-2.0.34
./configure –prefix=/usr/local/gd –with-jpeg=/usr/local/jpeg –with-png=/usr/local/png –with-freetype=/usr/lib –with-zlib
make && make install

6.安装PHP

wget http://cn.php.net/distributions/php-5.2.11.tar.gz

wget http://php-fpm.org/downloads/php-5.2.11-fpm-0.5.13.diff.gz
gunzip php-5.2.11-fpm-0.5.13.diff.gz
tar zxvf php-5.2.11.tar.gz
patch -d php-5.2.11 -p1 < php-5.2.11-fpm-0.5.13.diff
cd php-5.2.11
./configure –prefix=/usr/local/php –enable-mbstring –with-mysqli –enable-bcmath –enable-exif –enable-dba –enable-calendar –with-bz2 –enable-fastcgi –enable-fpm –enable-magic-quotes –enable-libxml –with-mcrypt –enable-ftp –with-gd –with-gettext –enable-gd-native-ttf –with-jpeg-dir=/usr/local/jpeg –with-ttf –enable-wddx –with-curl –with-pgsql –with-openssl –with-mhash –with-zlib –with-mysql –with-png-dir=/usr/local/png –enable-zip –enable-zend-multibyte –with-freetype-dir=/usr/lib –with-iconv=/usr/local/libiconv –enable-soap
make && make install