#!/bin/bash

# INSTALL Nginx+PHP5


yum -y install libxml2* libtool* pcre* gettext*


DIR=`pwd`

mkdir ${DIR}/Tmp 

#VERSION=`cat /etc/redhat-release | awk '{print $7}' | cut -c1`

VERSION=`lsb_release -r |awk '{print $2}' |cut -c1`


cp -r /usr/local/src/install_nginx/mysql_x86_64 /usr/local/mysql


Jpegsrc_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^Jpegsrc*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/jpeg-6b

if [ $VERSION -eq 6 ];then

\cp /usr/share/libtool/config/config.* .

else

\cp /usr/share/libtool/config.* .

fi

mkdir -p /usr/local/man/man1

./configure --prefix=/usr/local --enable-static --enable-shared

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Libpng_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^libpng*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

cp scripts/makefile.linux Makefile

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Freetype_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^freetype*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}



Libxml_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^libxml*`

tar jxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}



Libiconv_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^libiconv*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Libmcrypt_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^libmcrypt*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

if [ $VERSION != 6 ];then

rm -rf /usr/lib/libmcrypt.so.4

fi

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Mhash_Function(){

cd ${DIR}

File=`ls -1 |grep -i ^mhash*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

if [$VERSION != 6 ];then

rm -rf /usr/lib/libmhash.so.2

fi

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

}


Mcrypt_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^mcrypt*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

/sbin/ldconfig

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


GD_Function(){ 

cd ${DIR}

File=`ls -1 | grep -i ^gd*`

tar jxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure --prefix=/usr/local --with-jpeg=/usr/local --with-png=/usr/local

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Php_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^php.*tar.gz`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

gzip -cd ${DIR}/php-5.2.17-fpm-0.5.14.diff.gz | patch -d ${DIR}/Tmp/${File%.tar.*} -p1

'./configure'  '--with-config-file-path=/usr/local/webserver/php/etc' '--prefix=/usr/local/webserver/php' '--with-freetype-dir=/usr/local' '--with-mysql=/usr/local/mysql' '--with-zlib' '--enable-shared' '--with-curl' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--enable-mbstring=all' '--enable-mbregex' '--enable-gd-native-ttf' '--enable-fastcgi' '--enable-fpm' '--with-libxml-dir=/usr --enable-xml' '--enable-force-cgi-redirect' '--with-openssl' '--enable-sockets' '--disable-rpath' '--enable-discard-path' '--enable-safe-mode' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--enable-pcntl' '--with-iconv' '--with-mcrypt' '--with-mhash'

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /usr/local/webserver/php/etc/php.ini 

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Memcache_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^memcache*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tgz*}

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


EAccelerator_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^eaccelerator*`

tar jxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

/usr/local/webserver/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Pcre_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^pcre*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}


Nginx_Function(){

cd ${DIR}

File=`ls -1 | grep -i ^nginx*`

tar zxf ${File} -C ${DIR}/Tmp/

cd Tmp/${File%.tar*}

./configure  --user=nobody --group=nobody --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

if [ $? != 0 ];then

echo "${File}  ERROR !!!!!!!!!!!"

exit 10

fi

}



Jpegsrc_Function

Libpng_Function

Freetype_Function

#Libxml_Function

Libiconv_Function

Libmcrypt_Function

GD_Function

Mhash_Function

Mcrypt_Function

Php_Function

Memcache_Function

EAccelerator_Function

Pcre_Function

#Nginx_Function




cd /usr/local/src/install_nginx

#yes | cp conf/fcgi.conf /usr/local/webserver/nginx/conf/

#yes | cp conf/nginx.conf /usr/local/webserver/nginx/conf/

yes | cp conf/php-fpm.conf /usr/local/webserver/php/etc/

yes | cp conf/php.ini /usr/local/webserver/php/etc/