nginx + php(fastcgi)搭建高性能web服务器[v2]

星期五, 六月 11th, 2010

前面已经写过一篇《nginx + php(fastcgi)搭建高性能web服务器》,本文和上篇没什么区别,只是新增了openssl安装,并将其他的软件升级到最新版本。

本文在CentOS 5.1 x86_64平台通过测试;最后修改于2010-07-02

下载源码 (截止到2010年04月28日最新稳定版)
openssl-1.0.0.tar.gz
mysql-5.1.46.tar.gz
zlib-1.2.5.tar.gz
freetype-2.3.12.tar.gz
libpng-1.4.1.tar.gz
jpegsrc.v8a.tar.gz
gd-2.0.35.tar.gz
libiconv-1.13.1.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
libevent-1.4.13-stable.tar.gz
php-5.2.13-fpm-0.5.13.diff.gz
suhosin-patch-5.2.13-0.9.7.patch.gz
php-5.2.13.tar.gz
memcache-2.2.5.tgz
eaccelerator-0.9.6.tar.bz2
PDO_MYSQL-1.0.2.tgz"
ImageMagick-6.6.1-5.tar.gz
imagick-2.3.0.tgz
pcre-8.02.tar.gz
nginx-0.7.65.tar.gz

本站打包下载所有源码:
websuite-20100428.tar.gz

安装 opensll

tar zxvf openssl-1.0.0.tar.gz
cd openssl-1.0.0
./config shared zlib
make
make test
make install
 
创建连接
mv /usr/bin/openssl /usr/bin/openssl.OFF
mv /usr/include/openssl /usr/include/openssl.OFF
rm -rf /usr/lib/libssl.so
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ln -sv /usr/local/ssl/lib64/libssl.so.1.0.0 /usr/lib/libssl.so
 
配置库文件搜索路径
echo "/usr/local/ssl/lib64" >> /etc/ld.so.conf
ldconfig -v
 
检测安装结果
openssl version

安装 mysql

groupadd mysql
useradd mysql -g mysql -M -s /bin/false
tar zxvf mysql-5.1.46.tar.gz
cd mysql-5.1.46
./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --without-debug --with-big-tables \
--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread \
--enable-static --enable-assembler --enable-local-infile --with-readline --with-ssl \
--enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make
make install
 
以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。
如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
 
1、以mysql用户帐号的身份建立数据表:
chown -R mysql.mysql /usr/local/mysql
cp support-files/my-large.cnf /etc/my.cnf
scripts/mysql_install_db --user=mysql
 
2、加入开机自启动;并启动mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
service mysqld start

安装 zlib

tar zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure --prefix=/usr/local/zlib -s
make
make install
cd ..

安装 freetype

tar zxvf freetype-2.3.12.tar.gz
cd freetype-2.3.12
./configure --prefix=/usr/local/freetype
make
make install
cd ..

安装 libpng

tar zxvf libpng-1.4.1.tar.gz
cd libpng-1.4.1
./configure --prefix=/usr/local/libpng
make check
make install
cd ..

安装 jpeg

tar zxvf jpegsrc.v8a.tar.gz
cd jpeg-8a
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make
make test
make install
cd ..
 
在RHEL5 64 位下编译jpeg-8a时候报以下错误:
make: ./libtool: Command not found make: *** [jcapimin.lo] Error 127
错误分析:由于libtool版本过低导致的,进入jpeg-8a的源码目录,复制相关文件覆盖,然后重新configure
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .

安装 gd

tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype \
--with-png=/usr/local/libpng --with-zlib=/usr/local/zlib --enable-m4_pattern_allow
make
make install
cd ..

编译最新的2.0.35版本,make的时候出现以下错误:
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] Error 1

解决办法: configure的时候加上--enable-m4_pattern_allow参数;便能顺利编译安装

安装 libiconv

tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure
make
make install
cd ..

安装 libmcrypt

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads
make
make check
make install
cd libltdl
ldconfig
./configure --enable-ltdl-install
make
make install
cd ../..

安装 mhash

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
cd ..

安装 mcrypt

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure --with-libiconv-prefix
make
make install
cd ..

configure时候出现如下错误:
configure: error: "You need at least libmhash 0.8.15 to compile this program http://mhash.sf.net/"
前面已经安装过mhash,初步分析为预编译的时候没找到lib文件所在的地址;
所以在./configure前面加上LD_LIBRARY_PATH=/usr/local/lib

安装 libevent

tar -xzvf libevent-1.4.13-stable.tar.gz
cd /usr/local/libevent-1.4.13-stable/
./configure --prefix=/usr/local/libevent
make
make install
cd ..

安装 PHP(fastcgi模式)

tar zxvf php-5.2.13.tar.gz
 
安装php-fpm补丁
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
 
安装Sohusin应用补丁
gzip -cd suhosin-patch-5.2.13-0.9.7.patch.gz | patch -d php-5.2.13 -p1
 
cd php-5.2.13
./buildconf  --force
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg \
--with-png-dir=/usr/local/libpng --with-zlib=/usr/local/zlib --with-gd=/usr/local/gd \
--with-libevent=/usr/local/libevent --enable-safe-mode --enable-sockets \
--with-gdbm=/usr/lib --with-iconv-dir --enable-mbstring --enable-mbregex --with-curl \
--with-curlwrappers --enable-bcmath --with-mhash --with-mcrypt --enable-fastcgi \
--enable-fpm --with-pear --enable-force-cgi-redirect --enable-shmop --enable-xml \
--enable-sysvsem --enable-inline-optimization --enable-pcntl --enable-discard-path \
--with-libxml-dir --enable-suhosin --enable-zip
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ..

安装PHP5扩展模块

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
 
tar jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
 
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ..
 
tar zxvf ImageMagick-6.6.1-5.tar.gz
cd ImageMagick-6.6.1-5
./configure
make
make install
cd ..
 
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..

配置 PHP

vi /usr/local/php/etc/php.ini
查找 extension_dir = "./"
修改为 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
extension = "eaccelerator.so"
 
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/var/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"
 
再查找output_buffering = Off
修改为output_buffering = On
 
创建eaccelerator缓存目录
mkdir -p /var/cache/eaccelerator
chmod 777 /var/cache/eaccelerator

修改php-fpm.conf
使用默认配置文件,根据实际情况调整几个参数即可
max_children
rlimit_files
max_requests

或者使用本站推荐配置文件;点此 查看

安装 pcre

tar jxvf pcre-8.2.tar.gz
cd pcre-8.2
./configure
make
make check
make install
cd ..

安装 Nginx

mkdir /var/cache/nginx
tar zxvf nginx-0.7.65.tar.gz
cd nginx-0.7.65
./configure --prefix=/usr/local/nginx --http-client-body-temp-path=/var/cache/nginx/client_body_temp \
--with-select_module --with-poll_module --with-http_sub_module --with-http_stub_status_module \
--with-http_gzip_static_module --with-http_dav_module --with-http_flv_module --with-debug \
--with-http_ssl_module --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
make
make install
cd ..

nginx + php(fastcgi)搭建高性能web服务器[v1]

星期五, 十一月 20th, 2009

本文在CentOS 5.1\5.3平台通过测试;最后修改于2009-11-26

  • 下载源码 (截止到2009年11月20日最新稳定版)
  • 安装 mysql
  • groupadd mysql
    useradd mysql -g mysql -M -s /bin/false
    tar zxvf mysql-5.1.40.tar.gz
    cd mysql-5.1.40
    ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --without-debug --with-big-tables \ 
    --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread \
    --enable-static --enable-assembler --enable-local-infile --with-readline --with-ssl \
    --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
    make
    make install
     
    以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。
    如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
     
    1、以mysql用户帐号的身份建立数据表:
    chown -R mysql.mysql /usr/local/mysql
    cp support-files/my-large.cnf /etc/my.cnf
    scripts/mysql_install_db --user=mysql
     
    2、加入开机自启动;并启动mysql
    cp support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod 700 /etc/rc.d/init.d/mysqld
    chkconfig --add mysqld
    chkconfig --level 35 mysqld on
    service mysqld start
  • 安装GD库
    • 安装 zlib

      tar zxvf zlib-1.2.3.tar.gz
      cd zlib-1.2.3
      ./configure --prefix=/usr/local/zlib
      make
      make install
      cd ..

      安装 freetype

      tar zxvf freetype-2.3.8.tar.gz
      cd freetype-2.3.8
      ./configure --prefix=/usr/local/freetype
      make
      make install
      cd ..

      安装 libpng

      tar zxvf libpng-1.2.35.tar.gz
      cd libpng-1.2.35
      cp scripts/makefile.linux makefile
      make test
      make install
      cd ..

      安装 jpeg

      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
      ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
      make
      make install
      cd ..
       
      在RHEL5 64 位下编译jpeg-6b时候报以下错误:
      make: ./libtool: Command not found make: *** [jcapimin.lo] Error 127
      错误分析:由于libtool版本过低导致的,进入jpeg-6b的源码目录,复制相关文件覆盖,然后重新configure。
      cp /usr/share/libtool/config.sub .
      cp /usr/share/libtool/config.guess .

      安装 gd

      依赖gettext,同时需要将-fPIC选项加入到Makefile的CFLAG中,大约230行。 
      tar zxvf gd-2.0.35.tar.gz
      cd gd-2.0.35
      ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype \
      --with-png --with-zlib=/usr/local/zlib
      make
      make install
      cd ..

      编译最新的2.0.35版本,make的时候出现以下错误:
      configure.ac:64: error: possibly undefined macro: AM_ICONV
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
      make: *** [configure] Error 1

      解决办法: configure的时候加上--enable-m4_pattern_allow参数;便能顺利编译安装

  • 安装 libiconv
  • tar zxvf libiconv-1.12.tar.gz
    cd libiconv-1.12
    ./configure
    make
    make install
    cd ..
  • 安装 libmcrypt
  • tar zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configure --disable-posix-threads
    make
    make check
    make install
    cd libltdl
    ldconfig
    ./configure --enable-ltdl-install
    make
    make install
    cd ..
  • 安装 mhash
  • tar zxvf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9
    ./configure
    make
    make install
    cd ..
  • 安装 mcrypt
  • tar zxvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8
    LD_LIBRARY_PATH=/usr/local/lib ./configure --with-libiconv-prefix
    make
    make install
    cd ..

    configure时候出现如下错误:
    configure: error: "You need at least libmhash 0.8.15 to compile this program http://mhash.sf.net/"
    前面已经安装过mhash,初步分析为预编译的时候没找到lib文件所在的地址;
    所以在./configure前面加上LD_LIBRARY_PATH=/usr/local/lib

  • 安装 libevent
  • tar -xzvf libevent-1.4.9-stable.tar.gz
    cd /usr/local/libevent-1.4.9-stable/
    ./configure --prefix=/usr/local/libevent
    make
    make install
    cd ..
  • 安装 PHP(fastcgi模式)
  • tar zxvf php-5.2.11.tar.gz
    生成 php-fpm补丁
    tar zxvf php-fpm-0.6~5.2.11.tar.gz
    php-fpm-0.6-5.2.11/generate-fpm-patch
     
    安装Sohusin应用补丁
    gzip -d suhosin-patch-5.2.11-0.9.7.patch.gz
    cd php-5.2.11
    patch -p 1 -i ../suhosin-patch-5.2.11-0.9.7.patch
    cd ..
     
    安装 php-fpm补丁
    cd php-5.2.11
    patch -p1 < ../fpm.patch
    cd ..
     
    cd php-5.2.11
    ./buildconf  --force
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
    --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --with-freetype-dir=/usr/local/freetype--with-jpeg-dir=/usr/local/jpeg --with-png-dir \
    --with-zlib=/usr/local/zlib --with-gd=/usr/local/gd --with-libevent=/usr/local/libevent \
    --enable-safe-mode --enable-sockets --with-gdbm=/usr/lib --with-iconv-dir --enable-mbstring \
    --enable-mbregex --with-curl --with-curlwrappers --enable-bcmath --with-mhash --with-mcrypt \
    --enable-fastcgi --with-fpm --with-pear --enable-force-cgi-redirect --enable-shmop --enable-xml \
    --enable-sysvsem --enable-inline-optimization --enable-pcntl --enable-discard-path --with-libxml-dir \
    --enable-suhosin --enable-zip 
    make
    make install
    cp php.ini-dist /usr/local/php/etc/php.ini
    cd ..

    # PHP-FPM 0.6 for PHP 5.2.11的编译开关从enable改为了with, 要做相应修改,同时要增加--with-libevent开关
    # 加上--enable-suhosin 韩国的PHP 守护神补丁

    安装PHP5扩展模块

      tar zxvf memcache-2.2.5.tgz
      cd memcache-2.2.5/
      /usr/local/php/bin/phpize
      ./configure --with-php-config=/usr/local/php/bin/php-config
      make
      make install
      cd ..
       
      tar jxvf eaccelerator-0.9.5.3.tar.bz2
      cd eaccelerator-0.9.5.3/
      /usr/local/php/bin/phpize
      ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
      make
      make install
      cd ..
       
      tar zxvf PDO_MYSQL-1.0.2.tgz
      cd PDO_MYSQL-1.0.2/
      /usr/local/php/bin/phpize
      ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
      make
      make install
      cd ..
       
      tar zxvf ImageMagick-6.5.7-9.tar.gz
      cd ImageMagick-6.5.7-9/
      ./configure
      make
      make install
      cd ..
       
      tar zxvf imagick-2.3.0.tgz
      cd imagick-2.3.0/
      /usr/local/php/bin/phpize
      ./configure --with-php-config=/usr/local/php/bin/php-config
      make
      make install
      cd ..

      配置 PHP

      vi /usr/local/php/etc/php.ini
      查找 extension_dir = "./"
      修改为 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
      并在此行后增加以下几行,然后保存:
      extension = "memcache.so"
      extension = "pdo_mysql.so"
      extension = "imagick.so"
      extension = "eaccelerator.so"
       
      eaccelerator.shm_size="64"
      eaccelerator.cache_dir="/var/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"
       
      再查找output_buffering = Off
      修改为output_buffering = On
       
      创建eaccelerator缓存目录
      mkdir -p /var/cache/eaccelerator
      chmod 777 /var/cache/eaccelerator

    修改php-fpm.conf
    使用默认配置文件,根据实际情况调整几个参数即可
    max_children
    rlimit_files
    max_requests

    或者使用本站推荐配置文件;点此 查看

  • 安装 Nginx
  • tar jxvf pcre-8.0.tar.gz
    cd pcre-8.0
    ./configure
    make
    make check
    make install
    cd ..
     
    mkdir /var/cache/nginx
    tar zxvf nginx-0.7.51.tar.gz
    cd nginx-0.7.51
    ./configure --prefix=/usr/local/nginx --http-client-body-temp-path=/var/cache/nginx/client_body_temp \
    --with-select_module --with-poll_module --with-http_sub_module --with-http_stub_status_module \
    --with-http_gzip_static_module --with-http_dav_module --with-http_flv_module --with-debug \
    --with-http_ssl_module --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
    make
    make install
    cd ..

    参考文章:张宴的 Nginx 0.8.x + PHP 5.2.10(FastCGI)搭建胜过Apache十倍的Web服务器

    解决GD2依赖gettext

    星期五, 二月 27th, 2009
    安装php5需要gd2的支持,但在安装过程中,执行编译的时候出现下面的错误:
    root@web1 gd-2.0.35]# make
    cd . && /bin/sh /root/gd-2.0.35/config/missing --run aclocal-1.9 -I config
    aclocal:configure.ac:64: warning: macro `AM_ICONV' not found in library
    cd . && /bin/sh /root/gd-2.0.35/config/missing --run automake-1.9 --foreign
    cd . && /bin/sh /root/gd-2.0.35/config/missing --run autoconf
    configure.ac:64: error: possibly undefined macro: AM_ICONV
    If this token and others are legitimate, please use m4_pattern_allow.
    See the Autoconf documentation.
    make: *** [configure] Error 1
    把报错信息“configure.ac:64: error: possibly undefined macro: AM_ICONV”拿到google里搜索,得到“But you need to have gettext”没有gettext这个包。
    那好吧,我们来安装这个gettext。在rhel5中可以使用yum安装
    yum install gettex
    t

    很快就装好了,再执行make编译命令,一切ok!

    ---------------------------------------------------------------------------------------------
    后来在另外机器上编译GD的时候也出现了这个错误,gettext也已经安装了,但是依旧报错;后来在张微波的博客里看到configure的时候加 --enable-m4_pattern_allow 参数,加上后问题解决。

    解决安装软件时的/usr/local/lib/libz.a(compress.o)错误

    星期五, 八月 1st, 2008

    在安装 php 时,需要先安装 gd-2.0.33.tar.gz , 但在编译 gd-2.0.33.tar.gz 时出现了如下错误:

    /usr/bin/ld: /usr/local/lib/libz.a(compress.o): relocation R_X86_64_32 against `a local symbol' can not be used when

    making a shared object; recompile with -fPIC
    /usr/local/lib/libz.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make[2]: *** [libgd.la] 错误 1
    make[2]: Leaving directory `/usr/local/src/gd-2.0.33'
    make[1]: *** [all-recursive] 错误 1
    make[1]: Leaving directory `/usr/local/src/gd-2.0.33'
    make: *** [all] 错误 2

    解决办法 : 重新安装 zlib-1.2.3.tar.gz

    tar -zxvf zlib-1.2.3.tar.gz
    cd zlib-1.2.3
    ./configure

    vi Makefile
    找到 CFLAGS=-O3 -DUSE_MMAP
    在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
    接下面步骤

    make
    make install

    gd库的安装

    星期二, 四月 22nd, 2008

    在系统监控中一般借助图形直观显示,大多数绘图程序是php编写的。这些程序需要php支持图形库,以便提供必要的函数;为了支持更多的格式,需要安装gd库并重编译php。
    php默认的配置只能处理GIF图像,不能处理JPEG图像,gd库本来是支持GIF的,但由于GIF使用了有版权争议的LZW算法,会引起法律问题;从GD-1.6开始,GD库不再支持GIF,改为支持更好的,无版权争议的PNG。通过gd库可同时支持GIF, PNG和JPEG等。

    以下简述安装过程:

    安装freetype
    tar zxvf freetype-2.1.10.tar.gz
    ./configure
    make && make install

    安装zlib
    tar -zxvf zlib-1.2.3.tar.gz
    cd zlib.1.2.3
    ./configure
    make && make install

    安装libpng
    tar -zxvf libpng-1.2.8-config.tar.gz
    cd libpng-1.2.8-config
    cp scripts/makefile.std makefile
    make test
    make install

    安装jpeg
    tar -zxvf jpegsrc.v6b.tar.gz
    cd jpeg-6b
    ./configure --enable-share --enable-static
    make; make install

    安装GD
    tar -zxvf gd-2.0.33.tar.gz
    cd gd-2.0.33
    ./configure --prefix=/usr/local/gd --with-jpeg --with-png --with-zlib --with-freetype=/usr/local/freetype/lib
    make && make install

    重新编译 php,推荐4.4.1版本
    ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-gd --with-zlib --with-png --with-jpeg --with-freetype --enable-sockets
    make && make install