#!/bin/bash

#lamp_install

#definevariables

LY=lamp.tar.gz

DES_PATH=/usr/local/

YB_PATH=/usr/local/src/

SOU_PATH=/usr/src/

#lamp_check

lamp_check (){

[ ! -f$YB_PATH/$LY ] && echo "not found lamp.tar.gz" &&exit 1

#yum check

yum grouplist1>/dev/null

[ $? -ne 0 ]&& echo "ERROR: YUM NOT SET" && exit 1

#DevelopmentTools install

yum groupinstall"Development Tools" -y 1>/dev/null

wait

tar xf$YB_PATH/$LY -C $YB_PATH

}

#apache_install

apache_install(){

#check

[ ! -f$YB_PATH/bao/apr-1.4.6.tar.bz2 ] && echo "not foundapr-1.4.6.tar.bz2" && exit 1

[ ! -f$YB_PATH/bao/apr-util-1.5.1.tar.bz2 ] && echo "not foundapr-util-1.5.1.tar.bz2" && exit 1

[ ! -f$YB_PATH/bao/httpd-2.4.3.tar.gz ] && echo "not foundhttpd-2.4.3.tar.gz" && exit 1

#jieya

tar xf$YB_PATH/bao/apr-1.4.6.tar.bz2 -C $SOU_PATH

tar xf$YB_PATH/bao/httpd-2.4.3.tar.gz -C $SOU_PATH

tar xf$YB_PATH/bao/apr-util-1.5.1.tar.bz2 -C $SOU_PATH

cd $SOU_PATH

#apr-1.4.6install

cd apr-1.4.6/

if [ -xconfigure ];then

      ./configure --prefix=/usr/local/apr 1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"apr-1.4.6 install success"

                                  else

                                  echo"apr-1.4.6 install fail";exit 1

                                  fi

                       else

                      echo "apr-1.4.6 makefail";exit 1

                      fi

           else

           echo "apr-1.4.6 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#apr-util-1.5.1install

cd../apr-util-1.5.1/

if [ -xconfigure ];then

      ./configure --prefix=/usr/local/apr-util  1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"apr-util-1.5.1 install success"

                                  else

                                  echo"apr-util-1.5.1 install fail";exit 1

                                  fi

                      else

                      echo "apr-util-1.5.1make fail";exit 1

                      fi

           else

           echo "apr-util-1.5.1 configurefail";exit 1

           fi

   

else

echo"warnning: not found configure";exit 1

fi

#apache install

yum install zlib-devel  -y 1>/dev/null

wait

yum installopenssl-devel -y  1>/dev/null

wait

yum installpcre-devel -y  1>/dev/null

wait

cd../httpd-2.4.3/

if [ -xconfigure ];then

      ./configure --prefix=/usr/local/apache2--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/--enable-disk-cache --enable-static-support --enable-static-ab--disable-userdir --with-mpm=prefork --disable-ipv6  --with-sendfile 1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"httpd-2.4.3 install success"

                                  else

                                  echo"httpd-2.4.3 install fail";exit 1

                                  fi

                      else

                      echo "httpd-2.4.3make fail";exit 1

                      fi

           else

           echo "httpd-2.4.3 configurefail";exit 1

           fi

   

else

echo"warnning: not found configure";exit 1

fi

}

#mysql_install

mysql_install(){

cd $YB_PATH/bao/

#install pre

groupadd mysql

useradd -g mysqlmysql

rpm -icmake-2.6.4-7.el5.i386.rpm

yum removemysql-server mysql mysql-devel  ncurses-devellibtool bison gcc*  -y 1>/dev/null

#install

[  ! -f $YB_PATH/bao/mysql-5.5.29.tar.gz ]&& echo "not found mysql-5.5.29.tar.gz" && exit 1

tar xf $YB_PATH/mysql-5.5.29.tar.gz-C $SOU_PATH

cd mysql-5.5.29/

cmake  \

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"mysql-5.5.29 install success"

                                  else

                                  echo"mysql-5.5.29 install fail";exit 1

                                  fi

                      else

                      echo "mysql-5.5.29make fail";exit 1

                      fi

           else

           echo "mysql-5.5.29 cmakefail";exit 1

           fi

#tiaoguoyumingjiexi

cp support-files/etc/my.cnf

wait

sed -i -r '/socket/a\skip-name-resolve      = 1' /etc/my.cnf

#start mysql

/etc/init.d/mysqlsource  start

[ $? -ne 0 ]&& echo "mysql start fail" && exit 1

}

#phpinstall

php_install () {

cd $YB_PATH/bao/

#check

[ ! -f$YB_PATH/bao/libiconv-1.14.tar.gz ] && echo "not foundlibiconv-1.14.tar.gz" && exit 1

[ ! -f$YB_PATH/bao/libmcrypt-2.5.8.tar.gz ] && echo "not foundlibmcrypt-2.5.8.tar.gz " && exit 1

[ ! -f$YB_PATH/bao/mhash-0.9.9.9.tar.gz ] && echo "not foundmhash-0.9.9.9.tar.gz " && exit 1

[ ! -f$YB_PATH/bao/mcrypt-2.6.8.tar.gz ] && echo "not foundmcrypt-2.6.8.tar.gz" && exit 1

[ ! -f$YB_PATH/bao/php-5.4.11.tar.bz2 ] && echo "not foundphp-5.4.11.tar.bz2" && exit 1

tar xf$YB_PATH/bao/libiconv-1.14.tar.gz -C $SOU_PATH

tar xf$YB_PATH/bao/libmcrypt-2.5.8.tar.gz  -C$SOU_PATH

tar xf$YB_PATH/bao/mhash-0.9.9.9.tar.gz  -C$SOU_PATH

tar xf$YB_PATH/bao/mcrypt-2.6.8.tar.gz  -C$SOU_PATH

tar xf$YB_PATH/bao/php-5.4.11.tar.bz2 -C $SOU_PATH

#libiconv-1.14install

cd$SOU_PATH/libiconv-1.14

if [ -xconfigure ];then

      ./configure --prefix=/usr/local/--with-apr=/usr/local/apr 1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"libiconv-1.14 install success"

                                  else

                                  echo"libiconv-1.14 install fail";exit 1

                                  fi

                      else

                      echo "libiconv-1.14make fail";exit 1

                      fi

           else

           echo "libiconv-1.14 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#libmcrypt-2.5.8install

cd../libmcrypt-2.5.8

if [ -xconfigure ];then

      ./configure 1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"libmcrypt-2.5.8 install success"

                                  else

                                  echo"libmcrypt-2.5.8 intall fail";exit 1

                                  fi

                      else

                      echo "libmcrypt-2.5.8make fail";exit 1

                      fi

           else

           echo "libmcrypt-2.5.8 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#chongxinjiazaimokuai

/sbin/ldconfig

cd libltdl/

if [ -xconfigure ];then

      ./configure --enable-ltdl-install1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"libltdl install success"

                                  else

                                  echo"libltdl intall fail";exit 1

                                  fi

                      else

                      echo "libltdl makefail";exit 1

                      fi

           else

           echo "libltdl configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#mhash-0.9.9.9install

cd$SOU_PATH/mhash-0.9.9.9

if [ -xconfigure ];then

      ./configure  1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"mhash-0.9.9.9 install success"

                                  else

                                  echo"mhash-0.9.9.9 intall fail";exit 1

                                  fi

                      else

                      echo "mhash-0.9.9.9make fail";exit 1

                      fi

           else

           echo "mhash-0.9.9.9 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#mcrypt-2.6.8install

cd../mcrypt-2.6.8

if [ -xconfigure ];then

      ./configure 1>/dev/null

           if [ $? -eq 0 ];then

                 make 1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 0];then

                                  clear;echo"mcrypt-2.6.8 install success"

                                  else

                                  echo"mcrypt-2.6.8 intall fail";exit 1

                                  fi

                      else

                      echo "mcrypt-2.6.8make fail";exit 1

                      fi

           else

           echo "mcrypt-2.6.8 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#php-5.4.11install

cd ../php-5.4.11

yum installlibxml2-devel curl-devel libjpeg-devel freetype-devel net-snmp-devel -y  1>/dev/null

wait

if [ -xconfigure ];then

      ./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --enable-fpm--with-fpm-user=apache --with-fpm-group=apache --with-pcre-regex --with-zlib--with-bz2 --enable-calendar --disable-phar --with-curl  --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 --disable-ipv6 --disable-rpath--disable-debug --with-apxs2=/usr/local/apache2/bin/apxs 1>/dev/null

           if [ $? -eq 0 ];then

                 make ZEND_EXTRA_LIBS='-liconv'1>/dev/null

                      if [ $? -eq 0 ];then

                              makeinstall 1>/dev/null

                                  if [ $? -eq 1];then

                                  clear;echo"php-5.4.11 install success"

                                  else

                                  echo"php-5.4.11 intall fail";exit 1

                                  fi

                      else

                      echo "php-5.4.11 makefail";exit 1

                      fi

           else

           echo "php-5.4.11 configurefail";exit 1

           fi

else

echo"warnning: not found configure";exit 1

fi

#xiugaipeizhiwenjian

cpphp.ini-production /usr/local/php/etc/php.ini

sed -i '/AddTypeapplication\/x-gzip .gz .tgz/a\   AddType application\/x-httpd-php .php'/usr/local/apache2/conf/httpd.conf

sed -i's/DirectoryIndex index.html/DirectoryIndex index.php/'/usr/local/apache2/conf/httpd.conf

#qi dong php duli fu wu

ln -s/usr/local/apache2/bin/apachectl /etc/init.d/php-fpm

service php-fpmstart

}

lamp_check

apache_install

mysql_install

php_install