利用Nginx搭建高效Moodle学习平台

前期准备
一、 安装中科大yum源
1、将所有找到的yum包(有些需要加上–nodeps)(1、2步针对redhatlinux)
rpm -e –nodeps *.yum
2、到中科大的网站下载如下两个yum包并安装:
wget http://centos.ustc.edu.cn/centos/5.3/os/i386/CentOS/yum-3.2.19-18.el5.centos.noarch.rpm
wget http://centos.ustc.edu.cn/centos/5.3/os/i386/CentOS/yum-metadata-parser-1.1.2-2.el5.i386.rpm
rpm -ivh yum-metadata-parser-1.1.2-2.el5.i386.rpm
rpm -ivh yum-3.2.8-9.el5.centos.1.noarch.rpm
3、下载中科大专用的配置文件替换原有的yum配置文件:
#cd /etc/yum.repos.d/
#wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
#mv CentOS-Base.repo.5 CentOS-Base.repo
4、因为默认的配置文件中服务器地址用的版本号是变量$releasever,所以需要将其替换为实际的版本号,否则是无法连接到服务器的(最新版本可以到http://centos.ustc.edu.cn/centos/查询),当前CentOS最新版是5.5,所以我们修改CentOS-Base.repo
# Vim CentOS-Base.repo
   # :1,$s/$releasever/5.5/g   :wq 保存退出
二、利用yum安装升级所需的程序库
   yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl-devel pcre-devel

●安装MySQL数据库(可以到http://dev.mysql.com/downloads/下载最新版的mysql)
   #rpm –ivh MySQL-server-community-5.4.1-0.rhel5.i386.rpm
   #rpm –ivh MySQL-devel-community-5.4.1-0.rhel5.i386.rpm
   #rpm –ivh MySQL-client-community-5.4.1-0.rhel5.i386.rpm

编译安装PHP (FastCGI模式)使用php-fpm管理方式
一、PHP编译要用到的库

1、安装 libiconv.
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
#tar –xvf libiconv-1.13.1.tar.gz
#cd libiconv-1.13.1
#./configure --prefix=/usr   &&   make   && make install
2、安装mhash.
    #yum install –y mhash-devel
3、安装mcrypt
# yum install libmcrypt-devel
4、编译安装libevent
#wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
#tar –xvf libevent-1.4.13-stable.tar.gz
#./configure --prefix=/usr   &&   make   &&   make install
[建议不要使用yum的方式安装libevent,php-fpm建议Libevent 1.4.12-stable or higher is recommended, and at least libevent 1.4.3-stable is required,因此php-fpm需要1.4.3以上版本libevent的支持,所以去libevent的官网下最稳定版的libevent源码包进行编译安装]
二、下载并编译PHP(php-5.2.13与php-5.3.2编译参数不一样)
使用php-5.2.13

1、下载源码
# wget http://www.php.net/get/php-5.2.13.tar.gz/from/a/mirror   【php源码】
# wget http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz 【PHP-FPM补丁包】
2、解压安装
# tar –xvf php-5.2.13.tar.gz
      # gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1 【给php打补丁】
# cd php-5.2.13
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/var/lib/mysql --with-mysql=/usr/bin/mysql_config --with-iconv-dir=/usr --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap(如图一)

# make ZEND_EXTRA_LIBS='-liconv'
#make install

◆使用php-5.3.2
1、下载源码
# wget http://cn.php.net/distributions/php-5.3.2.tar.bz2 /*获取源码*/
# wget http://php-fpm.org/downloads/0.6/php-fpm-0.6~5.3.1.tar.gz   /*php-fpm补丁
# tar –xvf php-5.3.2.tar.bz2
#tar -zxvf php-fpm-0.6~5.3.1.tar.gz
# php-fpm-0.6-5.3.1/generate-fpm-patch
#cd php-5.3.2
# patch -p1 < ../fpm.patch
**重新安装autoconf系统自带的autoconf2.5.9重编译php-fpm时会提示错误,需要安装autoconf-2.13.tar.gz
卸载autoconf2.59,安装autoconf2.13
#rpm –e autoconf2.59
#wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz
#./buildconf --force
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/var/lib/mysql --with-mysql=/usr/bin/mysql_config --with-iconv-dir=/usr --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --with-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-libevent=shared (或--with—libevent=/usr/lib,当shared编译参数无效时使用这个参数)

# make ZEND_EXTRA_LIBS='-liconv'
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
pharcommand.inc
invertedregexiterator.inc
directorygraphiterator.inc
clicommand.inc
directorytreeiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.
#make install
错误提示:PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled
解决办法:从http://pear.php.net/go-pear下载个没有打包的PEAR安装包存储到本地命名为go-pear.php
运行:php go-pear.php

Notice: Following unknown configure options were used:
• –enable-fastcgi
• –enable-force-cgi-redirect
• –enable-discard-path
php 5.3.0 发现在默认状态下,已经开始支持 fastcgi了,不用再费劲再写配置参数了,如果写了,会提示如上错误信息,这个错误也可以忽略

三、编译安装PHP5扩展模块
1、 编译安装memcache-2.2.5.tgz
#Wget http://pecl.php.net/get/memcache-2.2.5.tgz
#tar –xvf 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
2、编译安装 eaccelerator-0.9.6-rc1.tar.bz2
#wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#tar –xvf eaccelerator-0.9.6.1.tar.bz2
#cd eaccelerator-0.9.6.1
# /usr/local/php/bin/phpiz
# ./configure --with-php-config=/usr/local/php/bin/php-config
3、编译安装PDO_MYSQL-1.0.2
#wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#/usr/local/php/bin/phpiz
#./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr &make &make install

编译安装ImageMagick
#wget ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/ImageMagick-6.6.3-0.tar.gz
   #./configure
   #make & make install

4、编译安装imagick
#wget http://pecl.php.net/get/imagick-3.0.0RC1.tgz
#tar -xf imagick3.0.0RC1.tgz
#cd imagick3.0.0RC1
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config    &make   &make install

5、编译安装mysqli
#cd php-5.3.2/ext/mysqli
#./configure --with-php-config=/usr/local/php/bin/php-config
#make   & make in

修改php.ini文件
  ★手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"  
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/" 【no-debug-non-zts-20060613名称可能不同】
  并在此行后增加以下几行,然后保存:
  extension = "memcache.so"
  extension = "pdo_mysql.so"
  extension = "imagick.so"
  再查找output_buffering = Off
  修改为output_buffering = On
★PHP 开启短标签支持
将php.ini 里的short_open_tag = off改成short_open_tag = On
   ★修改上传文件大小
    打开php.ini找到以下内容修改成以下值:
    upload_max_filesize = 20M ;   (默认是2M )
    max_execution_time = 300 ; ( 默认是 30 [seconds] )
post_max_size = 12M ;        ( 默认是 8M )

● 安装Nginx0.8.35
下载Nginx0.8.35
#wget http://nginx.org/download/nginx-0.8.35.tar.gz
一、安装pcre库
    方法一 用源码下载编译安装   ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre  
        可能会出现错误
     make时出现的错误:
“make -f objs/Makefile
make[1]: Entering directory `/home/nginx-0.7.65'
cd /usr/local/pcre \
       && if [ -f Makefile ]; then make distclean; fi \ && CC="gcc" CFLAGS="" \
       ./configure --disable-shared
/bin/sh: line 2: ./configure: 没有那个文件或目录
make[1]: *** [/usr/local/pcre/Makefile] 错误 127
make[1]: Leaving directory `/home/nginx-0.7.65'
make: *** [build] 错误 2”
解决办法,把手动安装的pcre卸了,make uninstall就行,然后让机器安装yum install pcre-devel版
      方法二 yum install pcre-devel
  
二、安装nginx
     ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
(可不用--with-pcre=/usr/local/lib)
/* --with-http_stub_status_module 是为了启用nginx 的NginxStatus 功能,用来监控Nginx 的当前状态*/
Nginx出现“413 Request Entity Too Large”错误
如果上传碰到“413 Request Entity Too Large”错误,请在nginx.conf增加 client_max_body_size 8m; 增加上传大小限制

解决方法:打开nginx主配置文件nginx.conf,找到http{}段,添加
client_max_body_size 20m;
Ubuntu下该文件在/etc/nginx/nginx.conf

posted @ 2010-12-07 16:13  孙同海  阅读(695)  评论(0编辑  收藏  举报