############ Nginx ,php,mongodb安装 #############

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 python-devel libicu-devel chrpath  nspr-devel readline-devel ncurses-devel boost boost-devel pcre-devel js-devel git tcsh scons js js-devel libevent libevent-devel subversion git-core tcsh tcl net-snmp net-snmp-devel net-snmp-utils 

################################################# PHP 安装 #############################################################

 
wget http://cn.php.net/distributions/php-5.4.0.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0
wget ftp://ftp.p_w_picpathmagick.org/pub/ImageMagick/ImageMagick-6.7.5-9.tar.gz
wget http://p_w_picpathmagick.linux-mirror.org/download/ImageMagick-6.7.6-1.tar.gz
wget http://pecl.php.net/get/imagick-3.0.1.tgz
wget http://downloads.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Feaccelerator%2F&ts=1332082481&use_mirror=nchc
#wget https://github.com/mongodb/mongo-php-driver/tarball/master
#wget http://pecl.php.net/get/mongo-1.2.6.tgz
wget http://pecl.php.net/get/mongo-1.2.10.tgz
wget http://pecl.php.net/get/memcache-3.0.6.tgz
wget http://pecl.php.net/get/memcached-2.0.1.tgz
wget https://launchpad.net/libmemcached/1.0/1.0.5/+download/libmemcached-1.0.5.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
wget https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
 
#编译安装PHP 5.4.0所需的支持库 
 
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make
make install
cd ../
 
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
 
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
 
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
 
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
 
 
############################## PHP #############################################
mkdir -p /usr/local/webserver/php 
mkdir -p /usr/local/webserver/php/etc
 
tar xvzf php-5.4.0.tar.gz
cd php-5.4.0
 
#./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/etc \
#--with-iconv-dir=/usr/local --enable-fpm  \
#--disable-phar --with-fpm-user=www-data --with-fpm-group=www-data --with-pcre-regex \
#--with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir \
#--enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir \
#--enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt  \
#--enable-pcntl  --enable-xml --disable-rpath  --enable-shmop --enable-sockets --enable-zip \
#--enable-bcmath --with-snmp
 
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-iconv-dir=/usr/local --with-freetype-dir --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-jpeg-dir --with-png-dir --with-zlib --with-zlib-dir --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 --without-pear --with-snmp --enable-gd-jis-conv 
 
 
 
 
 
make ZEND_EXTRA_LIBS='-liconv'
make test
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini
cd ../
 
############################## 编译安装PHP5扩展模块 #####################################
 
 
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
 
 
####################################################### 安装客户端和服务端 memcached ######################################
 
#先安装libevent:
tar zxvf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable
./configure --prefix=/usr/local/
make && make install
cd ../
 
##################### error memcached扩展不用安装,有memcache扩展 ########################
tar zxvf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure --with-libevent=/usr/local/
make && make install
cd ../
##################### error ########################
mkdir -p /usr/local/libmemcached/  
 
tar zxvf libmemcached-1.0.5.tar.gz
cd libmemcached-1.0.5
./configure --disable-64bit --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/  
make && make install  
cd ../
 
##################### error ########################
tar xvzf memcached-2.0.1.tgz
cd memcached-2.0.1
/usr/local/webserver/php/bin/phpize
./configure  --with-php-config=/usr/local/webserver/php/bin/php-config   --with-libmemcached-dir=/usr/local/libmemcached/  
make
make install
cd ../
##################### error ########################
 
 
############################## php mongo扩展 ########################################
tar -zxvf mongo-1.2.10.tgz
cd mongo-1.2.10
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make &&  make install
cd ../
 
### Installing shared extensions:     /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20100525/
 
 
#      Installing '/usr/lib/php/extensions/no-debug-zts-20060613/mongo.so'
# $ php -i | grep extension_dir
#        extension_dir => /usr/lib/php/extensions/no-debug-zts-20060613 =>
#      /usr/lib/php/extensions/no-debug-zts-20060613  
########################################################################################################################
 
tar zxvf ImageMagick-6.7.6-1.tar.gz
cd ImageMagick-6.7.6-1/
./configure
make
make install
cd ../
 
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
 
########################################## PHP 加速器 #################################################################
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
########################### 修改配置 ################################################################
 
 
####################### 修改php.ini文件 ##############################################################
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20100525/"\nextension = "memcache.so"\nextension = "mongo.so"\n#' /usr/local/webserver/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/webserver/php/etc/php.ini
sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/webserver/php/etc/php.ini
sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/webserver/php/etc/php.ini
 
date.timezone = "Asia/shanghai"
################### 配置eAccelerator加速PHP ############################
mkdir -p /usr/local/webserver/eaccelerator_cache
 
 
 
 
vi /usr/local/webserver/php/etc/php.ini
 
######################按shift+g键跳到配置文件的最末尾,加上以下配置信息:#############################
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
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"
 
 
#############创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
##################在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
#rm -f /usr/local/webserver/php/etc/php-fpm.conf
 
cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf
 
##############输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):
 
########################### 创建www用户和组,以及供blog.s135.com和www.s135.com两个虚拟主机使用的目录:#############################
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /usr/local/webserver/htdocs/ads
chmod +w /usr/local/webserver/htdocs/ads
chown -R www:www /usr/local/webserver/htdocs/ads
 
 
####################启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm
 
 
##################################################################################################################################
 
 
vi /usr/local/webserver/php/etc/php.ini 
 
#最后增加:
#;change nobody for www