之前的脚本没有添加mcrypt,本次添加了mcrypt,在安装这个东西的时候,遇到两个问题,所幸都解决了。已在脚本中做了标注! Mark......

  1. #!/bin/bash  
  2. #This script is used to auto install lamp .  
  3. #create by cheng  
  4. #mail:baoch8@163.com  
  5. #blog:http://myhat.blog.51cto.com  
  6. #version:20110630  
  7. #***************************
  8. #以上文件均可以在个人站点中获取。
  9. #只需要virtual.example.com换成postfixlinux.3322.org:8080即可。
  10. #***************************
  11. #相关的环境变量   
  12. lamp_path=/usr/src/lamp  
  13. lamp_log=/root/lamp_install.log   
  14. ip=`ifconfig eth0 | grep Bcast | awk -F ":" '{print $2}' | cut -d " " -f 1`  
  15. htdocs=/usr/local/apache2/htdocs   
  16. lamp_down=/root/lamp_down  
  17.  
  18. #modify hosts   
  19. grep virtual.example.com /etc/hosts   
  20. if [ "$?" = "1" ];then  
  21.     echo "192.168.10.6  virtual.example.com" >> /etc/hosts  
  22. fi  
  23.  
  24. if [ ! -d /root/lamp_down ];then  
  25.     mkdir /root/lamp_down  
  26. fi  
  27.  
  28. #download lamp packet  
  29. wget http://virtual.example.com/tar_tools/lamp/httpd/httpd-2.0.55.tar.bz2 -P $lamp_down  
  30.  
  31. wget http://virtual.example.com/tar_tools/lamp/freetype/freetype-2.3.9.tar.bz2 -P $lamp_down  
  32.  
  33. wget http://virtual.example.com/tar_tools/lamp/gd/gd-2.0.33.tar.gz -P $lamp_down  
  34.  
  35. wget http://virtual.example.com/tar_tools/lamp/jpeg/jpegsrc.v7.tar.gz -P $lamp_down  
  36.  
  37. wget http://virtual.example.com/tar_tools/lamp/libpng/libpng-1.5.2.tar.gz -P $lamp_down  
  38.  
  39. wget http://virtual.example.com/tar_tools/lamp/mysql/mysql-5.1.36.tar.gz -P $lamp_down  
  40.  
  41. wget http://virtual.example.com/tar_tools/lamp/php/php-5.2.17.tar.bz2 -P $lamp_down  
  42.  
  43. wget http://virtual.example.com/tar_tools/lamp/mcrypt/libmcrypt-2.5.8.tar.gz  -P $lamp_down  
  44.  
  45. wget http://virtual.example.com/tar_tools/lamp/mcrypt/mcrypt-2.6.8.tar.gz -P $lamp_down  
  46.  
  47. wget http://virtual.example.com/tar_tools/lamp/mcrypt/mhash-0.9.9.9.tar.bz2 -P $lamp_down  
  48.  
  49.  
  50. if [ ! -d /usr/src/lamp ];then  
  51.     mkdir /usr/src/lamp  
  52. fi  
  53.  
  54. #uncompress file  
  55. cd   
  56. for i in $lamp_down/*.tar.gz   
  57. do  
  58.     tar -xzf $i -C $lamp_path  
  59. done  
  60.  
  61. for i in $lamp_down/*.tar.bz2  
  62. do  
  63.     tar -xjf $i -C $lamp_path  
  64. done  
  65.  
  66. #Apache install  
  67. echo "Apache install start!"  
  68. cd $lamp_path/httpd-2.0.55/  
  69. ./configure --prefix=/usr/local/apache2 --enable-so  \  
  70. --enable-rewrite --enable-vhost-alias --enable-http \  
  71. --enable-static-htpasswd   
  72. make && make install   
  73. #建个软链接方便之后使用  
  74. ln  -s /usr/local/apache2/bin/apachectl /bin/apachectl  
  75.  
  76. #modity ServerName DirectoryIndex options  
  77. sed -i '292c\ServerName ($ip):80' /usr/local/apache2/conf/httpd.conf  
  78.  
  79. sed -i '394c\DirectoryIndex index.php index.html index.html.var' /usr/local/apache2/conf/httpd.conf  
  80.  
  81. #test apache configure  
  82. /bin/apachectl -t >> $lamp_log  
  83. echo "`date` Apache is Installed"  >> $lamp_log  
  84. #这里我选择关掉了selinux,如果不关的话,会提示php5.so无法加载的问题。  
  85. sed -i '6c\SELINUX=disabled' /etc/selinux/config  
  86.  
  87. /bin/apachectl start && echo "`date` Apache is started Good!" >> $lamp_log  
  88.  
  89. #Freetype Install  
  90. echo "`date` Freetype install start" >> $lamp_log  
  91. cd $lamp_path/freetype-2.3.9/  
  92. ./configure --prefix=/usr/local/freetype && make && make install  
  93. echo "`date` Freetype is  installed" >> $lamp_log  
  94.  
  95. #JPEG install  
  96. echo "`date` jpeg install start" >> $lamp_log  
  97. cd $lamp_path/jpeg-7  
  98. ./configure --prefix=/usr/local/jpeg7 && make && make install   
  99. echo "`date` jpeg is installed" >> $lamp_log  
  100.  
  101. #libpng Install  
  102. echo "`date` libpng  install start" >> $lamp_log  
  103. cd $lamp_path/libpng-1.5.2  
  104. ./configure --prefix=/usr/local/libpng && make && make install   
  105. echo "`date`libpng is installed" >> $lamp_log  
  106.  
  107. #gd install  
  108. echo "`date`gd start install" >> $lamp_log  
  109. cd $lamp_path/gd-2.0.33  
  110. ./configure --prefix=/usr/local/gd --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/jpeg7   
  111.  
  112. #modify gd_png.c 没办法啊,不修改这个文件,gd就不能make,修改文件。先删除,再添加。其实可以直接添加的。  
  113. sed -i '/png.h/d' gd_png.c   
  114. sed -i '15c\#include "/usr/local/libpng/include/png.h" ' gd_png.c   
  115.  
  116. make && make install   
  117. echo "`date` gd is installed" >> $lamp_log   
  118.  
  119. #libmcrypt  
  120. echo "`date` libmcrypt start install" >> $lamp_log  
  121. cd $lamp_path/libmcrypt-2.5.8   
  122. ./configure && make && make install  
  123. echo "`date` libmcrypt is installed" >> $lamp_log  
  124.  
  125. #安装完libmcrypt后,居然不能安装mcrypt,说找不到libmcrypt,让我重装。靠!什么情况。。。;0 :    
  126. export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH  
  127. #mhash   
  128. echo "`date` mhash start install" >> $lamp_log  
  129. cd $lamp_path/mhash-0.9.9.9  
  130. ./configure --prefix=/usr/local/mhash  make && make install  
  131. echo "`date` mhash in installed" >> $lamp_log  
  132.  
  133. #看看网友的解决办法   
  134. #http://hi.baidu.com/sodingli/blog/item/c897264b4f05812b08f7ef05.html/cmtid/9f465386c1f70724c75cc308  
  135. #http://woyoo.org/linux/centos5-install-mcrypt-2-6-8-error.html  
  136.  
  137. #为防止意外,我再做一次。  
  138. export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH  
  139.  
  140. #mcrypt  
  141. echo "`date` mcrypt start install" >> $lamp_log  
  142. cd $lamp_path/mcrypt-2.6.8  
  143. ./configure --prefix=/usr/local/mcrypt --with-libmcrypt-prefix=/usr/local/libmcrypt && make && make install   
  144. echo "`date` mcrypt is installed" >> $lamp_log  
  145.  
  146. #Mysql Install   
  147. useradd mysql  && echo "`date` user mysql added" >> $lamp_log  
  148. cd $lamp_path/mysql-5.1.36  
  149. ./configure --prefix=/usr/local/mysql --enable-local-infile --with-charset=utf8  --with-extra-charsets=gb2312,gbk --with-pthread --without-debug --enable-thread-safe-client && make && make install   
  150.  
  151. echo "`date` mysql is installed " >> $lamp_log  
  152.  
  153. #about configure file  
  154. cp $lamp_path/mysql-5.1.36  
  155. cp support-files/my-large.cnf /etc/my.cnf  
  156. chown -R mysql.mysql /usr/local/mysql  
  157. #pre databases  
  158. /usr/local/mysql/bin/mysql_install_db --user=mysql 
  159. #service file  
  160. cp $lamp_path/mysql-5.1.36/support-files/mysql.server /etc/init.d/mysql5  
  161. chmod 755 /etc/init.d/mysql5  
  162.  
  163. #start mysql5  
  164. /etc/init.d/mysql5 start  && echo "`date` mysql service is ready" >> $lamp_log  
  165.  
  166. #PHP install   
  167. echo "`date` php-5.2.17 start install " >> $lamp_log  
  168. cd $lamp_path/php-5.2.17  
  169.  
  170. ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local/jpeg7/ --with-gd=/usr/local/gd/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --enable-mbregex --with-mysql=/usr/local/mysql/ --with-pdo-mysql=/usr/local/mysql/  --with-mcrypt=/usr/local/mcrypt && make && make install   
  171.  
  172. #copy file and write to log  
  173. cp $lamp_path/php-5.2.17/php.ini-recommended /usr/local/php5/lib/php.ini && \  
  174.  
  175. echo "`date` php.ini file is copyed to /usr/local/php5/lib/" >> $lamp_log  
  176.  
  177. echo "application/x-httpd-php  php" >> /usr/local/apache2/conf/mime.types  
  178.  
  179. #安装完PHP后,相关的PHP页面可以正常打开。唯有phpinfo的测试页面不能打开,Google后,原来要开始short_open_tar.奇怪的是,在没有安装mcrypt之有,都可以打开phpinfo的测试页面。  
  180. sed -i '132c\short_open_tag = On' /usr/local/php5/lib/php.ini  
  181.  
  182. #edit test.php  
  183. touch $htdocs/test.php  
  184. cat >> $htdocs/test.php << CHENG 
  185. <? 
  186. phpinfo();  
  187. ?> 
  188. CHENG  
  189.  
  190. #about phpmyadmin  
  191. cd   
  192. wget http://virtual.example.com/tar_tools/lamp/phpmyadmin/phpMyAdmin-3.4.2-all-languages.tar.gz -P $lamp_down  
  193. cd $lamp_down  
  194. tar -xzf phpMyAdmin-3.4.2-all-languages.tar.gz   
  195. mv  phpMyAdmin-3.4.2-all-languages $htdocs/phpmyadmin  
  196. cd $htdocs/phpmyadmin   
  197. #configure phpmyadmin use root nopasswd  
  198. mv config.sample.inc.php config.inc.php  
  199. sed -i '17c\$cfg['blowfish_secret'] = 'baocheng';' config.inc.php  
  200. sed -i '36c\$cfg['Servers'][$i]['AllowNoPassword'] = true;' config.inc.php  
  201.  
  202. #start  
  203. echo "/bin/apachectl start " >> /etc/rc.local  
  204. echo "/etc/init.d/mysql5 start" >> /etc/rc.local  
  205.  
  206. echo "##########warning#############" >> $lamp_log  
  207. echo "Go to http://$ip/test.php" >> $lamp_log  
  208. echo "Mysql port 3306 and socket_file is  /tmp/mysql5.socket" >> $lamp_log  
  209. echo "Go to phpmyadmin http://$ip/phpmyadmin " >> $lamp_log  
  210. echo " user=root  paswd=null>> $lamp_log  
  211. echo "About selinux:disable" >> $lamp_log  
  212. echo "##########end################" >> $lamp_log   
  213. #重启是为了让selinux被关闭后能生效。  
  214. echo "Reboot system Now"