1. #!/bin/bash 

定义变量localpath为当前脚本的路径,作用是在后面使用变量来寻找程序包;
 

 
  
  1. localpath=`pwd`   

判断是否存在文件/tmp/lamp_lock,如果有这个文件表明这个脚本已经运行了,作用是防止重复运行脚本。如果没有这个文件,这创建该文件,并继续后面的步骤;

 
  
  1. if [ -e /tmp/lamp_lock ]    
  2. then     
  3.     echo "This script is running..."   
  4.     exit 9    
  5. fi    
  6. touch /tmp/lamp_lock  

检查当前的操作系统和用户是不是满足安装的需求;

 
  
  1. system=`uname`    
  2. if [ ! ${system}=Linux ]    
  3. then     
  4.     echo "You system is not rhel 5.5!!"   
  5.     exit 11    
  6. fi    
  7. user=`echo $UID`    
  8. if [ ! $user=0 ]    
  9. then     
  10.     echo "You are not root!"   
  11.     exit 10    
  12. fi   

自定义函数,函数的作用是判断返回值是否为0;

 
  
  1. jubgement() {    
  2. if [ ! $?=0 ]    
  3. then   
  4.     echo "Is error!!!"   
  5.     exit    
  6. fi    
  7. }   

用函数定义安装软件的版本,方便更改;

 
  
  1. phpver="5.2.14"   
  2. httpdver="2.2.11"   
  3. mysqlver="5.5.3-m3"   
  4. mhashver="0.9.9.9"   
  5. convver="1.13.1"   
  6. libmcver="2.5.8"   
  7. mcryptver="2.6.8"   
  8. pdover="1.0.2"   
  9. eAccver="0.9.6.1"  

解压缩;

 
  
  1. tar fxz php-${phpver}.tar.gz 2>>/tmp/error.log    
  2. tar fxj httpd-${httpdver}.tar.bz2 2>>/tmp/error.log    
  3. tar fxz mysql-${mysqlver}.tar.gz 2>>/tmp/error.log    
  4. tar fxz libiconv-${convver}.tar.gz 2>>/tmp/error.log    
  5. tar fxz libmcrypt-${libmcver}.tar.gz 2>>/tmp/error.log    
  6. tar fxz mcrypt-${mcryptver}.tar.gz 2>>/tmp/error.log    
  7. tar fxz mhash-${mhashver}.tar.gz 2>>/tmp/error.log    
  8. tar fxz PDO_MYSQL-${pdover}.tgz 2>>/tmp/error.log    
  9. tar fxj eaccelerator-${eAccver}.tar.bz2 2>>/tmp/error.log   
安装配置apache,并做了一个apache的启动脚本;
 
  
  1. cd ${localpath}/httpd-${httpdver}    
  2. ./configure --with-mpm=prefork --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atormics --enable-mods-shared=most --enable-so 2>>/tmp/error.log    
  3. jubgement    
  4. make && make install 2>>/tmp/error.log    
  5. jubgement    
  6. cat > /etc/rc.d/init.d/apache << EOF    
  7. #!/bin/bash    
  8. case \$1 in   
  9.     start )    
  10.     /usr/local/apache2/bin/apachectl \$1    
  11.     echo "apache                [start]"   
  12.     ;;    
  13.     stop )    
  14.     /usr/local/apache2/bin/apachectl \$1    
  15.     echo "apache                [stop]"   
  16.     ;;    
  17.     restart )    
  18.     /usr/local/apache2/bin/apachectl \$1    
  19.     echo "apache                [stop]"   
  20.     sleep 2    
  21.     echo "apache                [start]"   
  22. esac    
  23. EOF    
  24. chmod a+x /etc/rc.d/init.d/apache     
  25. service apache start 2>>/tmp/error.log    
  26. sleep 5   
安装配置MySQL;
 
  
  1. CFLAGS="-06 -mpentumpro -fomit-frame-pointer"   
  2. CXXFLAGS="-06 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti"   
  3. yum install gcc gcc-c++ ncurses-devel libtool -y  >& /dev/null   
  4. cd ${localpath}/mysql-${mysqlver}    
  5. useradd mysql    
  6. ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-ssl  --with-embedded-server --enable-local-infile --with-plugins=innobase --enable-static --with-client-ldflgs=-all-static --with-mysqld-ldflags=-all-static 2>>/tmp/error.log    
  7. jubgement    
  8. make && make install 2>>/tmp/error.log    
  9. jubgement    
  10. cat ${localpath}/mysql-${mysqlver}/support-files/my-huge.cnf > /etc/my.cnf    
  11. cat /usr/local/mysql/share/mysql/mysql.server > /etc/init.d/mysql    
  12. chmod a+x /etc/init.d/mysql    
  13. /usr/local/mysql/bin/mysql_install_db --user=mysql    
  14. chown mysql:mysql /usr/local/mysql -R    
  15. mkdir /usr/local/mysql/data    
  16. sed -i.bak '/\[mysqld\]/a datadir=\/usr\/local\/mysql\/data' /etc/my.cnf    
  17. cat /etc/my.cnf|grep skip-name-resolve || sed -i '/\[mysqld\]/a skip-name-resolve' /etc/my.cnf    
  18. echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf    
  19. ldconfig    
  20. ln -s /usr/local/mysql/bin/* /usr/local/bin/    
  21. ln -s /usr/local/mysql/libexec/* /usr/local/libexec/    
  22. ln -s /usr/local/mysql/share/man/man1/* /usr/share/man/man1/    
  23. ln -s /usr/local/mysql/share/man/man5/* /usr/share/man/man5/     
  24. service mysql start 2>>/tmp/error.log    
  25. sleep 5   
安装并配置PHP
 
  
  1. cd ${localpath}/libiconv-${convver}    
  2. ./configure 2>>/tmp/error.log    
  3. jubgement    
  4. make && make install 2>>/tmp/error.log    
  5. jubgement    
  6. cd ${localpath}/libmcrypt-${libmcver}    
  7. ./configure 2>>/tmp/error.log    
  8. jubgement    
  9. make && make install 2>>/tmp/error.log    
  10. jubgement    
  11. ldconfig    
  12. cd libltdl    
  13. ./configure --enable-ltdl-install    
  14. jubgement    
  15. make && make install    
  16. jubgement    
  17. cd ${localpath}/mhash-${mhashver}    
  18. ./configure 2>>/tmp/error.log    
  19. jubgement    
  20. make && make install 2>>/tmp/error.log    
  21. jubgement    
  22. cd ${localpath}/mcrypt-${mcryptver}    
  23. ./configure 2>>/tmp/error.log    
  24. jubgement    
  25. make && make install 2>>/tmp/error.log    
  26. jubgement    
  27. mount /dev/cdrom /mnt    
  28. yum -y install libjpeg* libpng* libxml2* zlib* glibc* glib2* bzip2* nvurses* curl* libidn* openssl* freetype*    
  29. cd ${localpath}/php-${phpver}    
  30. ./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-apxs2=/usr/local/apache2/bin/apxs --with-iconv-dir=/usr/local/ --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-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-tty 2>>/tmp/error.log    
  31. jubgement    
  32. make ZEND_EXTRA_LIBS='-liconv' 2>>/tmp/error.log    
  33. jubgement    
  34. make install 2>>/tmp/error.log    
  35. jubgement    
  36. cp ${localpath}/php-${phpver}/php.ini-dist /usr/local/php/etc/php.ini    
  37. echo "AddType text/html .php" >> /usr/local/apache2/conf/httpd.conf    
  38. echo "AddHandler php5-script .php" >> /usr/local/apache2/conf/httpd.conf    
  39. sed -i.bak '/IfModule mime_module/a\ \ \ \ AddType application/x-httpd-php .php' /usr/local/apache2/conf/httpd.conf    
  40. cat > /usr/local/apache2/htdocs/index.php << EOF    
  41. <? phpinfo() ?>    
  42. EOF    
  43. cat > /usr/local/apache2/htdocs/test.html << EOF    
  44. $link=mysql_connect('localhost','root','')    
  45. if (!$link) {    
  46.     die ('Could not connect:' mysql_error())    
  47. }    
  48. echo '<h1>Connected successfully</h1>';    
  49. phpinfo();    
  50. ?>    
  51. EOF    
  52. service apache stop 2>>/tmp/error.log    
  53. service apache start 2>>/tmp/error.log    
  54. rm -fr /tmp/lamp_lock    
  55. echo "include /usr/local/apache2/conf/prefork.c" >>/usr/local/apache2/conf/httpd.conf    
  56. cat > /usr/local/apache2/conf/prefork.c << EOF    
  57. <IfModule prefork.c>    
  58. startServers    8    
  59. MinSpareServers 5    
  60. MaxSpareServers 20    
  61. ServerLimit     20000    
  62. MaxClients      20000    
  63. MaxRequestsPerChild     2000    
  64. </IfModule>    
  65. EOF    
  66. cd ${localpath}/PDO_MYSQL-${pdover}    
  67. /usr/local/php/bin/phpize    
  68. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql    
  69. jubgement    
  70. make && make install    
  71. jubgement    
  72. sed -i.bak '/extension_dir =/  s/.\//\/usr\/local\/php\/lib\/extensions\/no-debug-non-zts-20060613/g' /usr/local/php/etc/php.ini    
  73. sed -i.bak '/extension_dir =/a  extension = "pdo_mysql.so"' /usr/local/php/etc/php.ini    
  74. echo "extension = pdo_mysql.so" >> /usr/local/php/etc/php.ini    
  75. cd ${localpath}/eaccelerator-${eAccver}    
  76. /usr/local/php/bin/phpize    
  77. ./configure --enable-eaccelerator=share --with-php-config=/usr/local/php/bin/php-config    
  78. echo "    
  79. [eaccelerator]    
  80. zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"   
  81. eaccelerator.shm_size="128"   
  82. eaccelerator.cache_dir="/tmp/eaccelerator_cache"   
  83. eaccelerator.enable="1"   
  84. eaccelerator.oprimizer="1"   
  85. eaccelerator.check_mtime="1"   
  86. eaccelerator.debug="0"   
  87. eaccelerator.filter=" "   
  88. eaccelerator.shm_ttl="300"   
  89. eaccelerator.shm_prune_period="120"   
  90. eaccelerator.shm_only="0"   
  91. eaccelerator.compress="1"   
  92. eaccelerator.compress_level="9"" >>/usr/local/php/etc/php.ini