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 ..