LAMP自动化安装脚本

来源:互联网 发布:光束灯编程 编辑:程序博客网 时间:2024/04/29 11:58

最近在搞LAMP,每次环境被破坏后,重新安装花不少时间,整个自动化脚本吧。

因为是依照内网环境写的,关于下载地址的部分不同环境请自行修改。

  1. #!/bin/bash 
  2.  
  3. #This script is used to auto install lamp . 
  4. #create by cheng 
  5. #mail:baoch8@163.com 
  6. #blog:http://myhat.blog.51cto.com 
  7. #version:20110629 
  8.  
  9. #env  
  10. lamp_path=/usr/src/lamp 
  11. lamp_log=/root/lamp_install.log  
  12. ip=`ifconfig eth0 | grep Bcast | awk -F ":" '{print $2}' | cut -d " " -f 1` 
  13. htdocs=/usr/local/apache2/htdocs  
  14. lamp_down=/root/lamp_down 
  15. #modify hosts  
  16. grep virtual.example.com /etc/hosts  
  17. if [ "$?" = "1" ];then 
  18.     echo "192.168.10.6  virtual.example.com" >> /etc/hosts 
  19. fi 
  20.  
  21. if [ ! -d /root/lamp_down ];then 
  22.     mkdir /root/lamp_down 
  23. fi 
  24.  
  25. #download lamp packet 
  26. wget http://virtual.example.com/tar_tools/lamp/httpd-2.0.55.tar.bz2 -P $lamp_down 
  27. wget http://virtual.example.com/tar_tools/lamp/freetype-2.3.9.tar.bz2 -P $lamp_down 
  28. wget http://virtual.example.com/tar_tools/lamp/gd-2.0.33.tar.gz -P $lamp_down 
  29. wget http://virtual.example.com/tar_tools/lamp/jpegsrc.v7.tar.gz -P $lamp_down 
  30. wget http://virtual.example.com/tar_tools/lamp/libpng-1.5.2.tar.gz -P $lamp_down 
  31. wget http://virtual.example.com/tar_tools/lamp/mysql-5.1.36.tar.gz -P $lamp_down 
  32. wget http://virtual.example.com/tar_tools/lamp/php-5.2.17.tar.bz2 -P $lamp_down 
  33.  
  34. if [ ! -d /usr/src/lamp ];then 
  35.     mkdir /usr/src/lamp 
  36. fi 
  37.      
  38. #uncompress file 
  39. cd  
  40. for i in $lamp_down/*.tar.gz  
  41. do 
  42.     tar -xzf $i -C $lamp_path 
  43. done 
  44.  
  45. for i in $lamp_down/*.tar.bz2 
  46. do 
  47.     tar -xjf $i -C $lamp_path 
  48. done 
  49.  
  50. #Apache install 
  51. echo "Apache install start!" 
  52.  
  53. cd $lamp_path/httpd-2.0.55/ 
  54. ./configure --prefix=/usr/local/apache2 --enable-so  \ 
  55. --enable-rewrite --enable-vhost-alias --enable-http \ 
  56. --enable-static-htpasswd  
  57. sleep 10  
  58. make && make install  
  59. sleep 8 
  60. ln  -s /usr/local/apache2/bin/apachectl /bin/apachectl 
  61.  
  62. #modity ServerName DirectoryIndex options 
  63. sed -i '292c\ServerName $ip:80' /usr/local/apache2/conf/httpd.conf 
  64. sed -i '394c\DirectoryIndex index.php index.html index.html.var' /usr/local/apache2/conf/httpd.conf 
  65.  
  66. #test apache configure 
  67. /bin/apachectl -t >> $lamp_log 
  68.  
  69. echo "`date` Apache is Installed"  >> $lamp_log 
  70. sed -i '6c\SELINUX=disabled' /etc/selinux/config 
  71.  
  72.  
  73. /bin/apachectl start && echo "`date` Apache is started Good!" >> $lamp_log 
  74. echo "`date` Please modify httpd.conf ServerName Option" >> $lamp_log 
  75. #Freetype Install 
  76. echo "`date` Freetype install start" >> $lamp_log 
  77. cd $lamp_path/freetype-2.3.9/ 
  78. ./configure --prefix=/usr/local/freetype  
  79. make && make install 
  80. sleep 5 
  81. echo "`date` Freetype is  installed" >> $lamp_log 
  82. sleep 10 
  83.  
  84. #JPEG install 
  85. echo "`date` jpeg install start" >> $lamp_log 
  86. cd $lamp_path/jpeg-7 
  87. ./configure --prefix=/usr/local/jpeg7  
  88. make && make install  
  89. echo "`date` jpeg is installed" >> $lamp_log 
  90. sleep 8 
  91.  
  92. #libpng Install 
  93. echo "`date` libpng  install start" >> $lamp_log 
  94. cd $lamp_path/libpng-1.5.2 
  95. ./configure --prefix=/usr/local/libpng 
  96. make && make install  
  97. echo "`date`libpng is installed" >> $lamp_log 
  98. sleep 10 
  99.  
  100. #gd install 
  101. echo "`date`gd start install" 
  102. cd $lamp_path/gd-2.0.33 
  103. ./configure --prefix=/usr/local/gd \ 
  104. --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype \ 
  105. --with-jpeg=/usr/local/jpeg7  
  106. #modify gd_png.c 
  107. sed -i '/png.h/d' gd_png.c  
  108. sed -i '15c\#include "/usr/local/libpng/include/png.h" ' gd_png.c  
  109.  
  110. make && make install  
  111. echo "`date` gd is installed" >> $lamp_log 
  112. #Mysql Install  
  113.  
  114. useradd mysql  && echo "`date` user mysql added" >> $lamp_log 
  115.  
  116. cd $lamp_path/mysql-5.1.36 
  117. ./configure --prefix=/usr/local/mysql --enable-local-infile --with-charset=utf8  --with-extra-charsets=gb2312,gbk --with-pthread --without-debug --enable-thread-safe-client  
  118.  
  119. make && make install  
  120.  
  121. echo "`date` mysql is installed " >> $lamp_log 
  122. #about configure file 
  123. cp $lamp_path/mysql-5.1.36 
  124. cp support-files/my-large.cnf /etc/my.cnf 
  125. chown -R mysql.mysql /usr/local/mysql 
  126.  
  127. #pre databases 
  128. /usr/local/mysql/bin/mysql_install_db --user=mysql 
  129. #service file 
  130. cp $lamp_path/mysql-5.1.36/support-files/mysql.server /etc/init.d/mysql5 
  131. chmod 755 /etc/init.d/mysql5 
  132. #start mysql5 
  133. /etc/init.d/mysql5 start  && echo "`date` mysql service is ready" >> $lamp_log 
  134.  
  135.  
  136. #PHP install  
  137. echo "`date` php-5.2.17 start install " >> $lamp_log 
  138. cd $lamp_path/php-5.2.17 
  139. ./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/  
  140. make && make install  
  141.  
  142. #copy file and write to log 
  143. cp $lamp_path/php-5.2.17/php.ini-recommended /usr/local/php5/lib/php.ini && \ 
  144. echo "`date` php.ini file is copyed to /usr/local/php5/lib/" >> $lamp_log 
  145. echo "application/x-httpd-php  php" >> /usr/local/apache2/conf/mime.types 
  146.  
  147. #edit test.php 
  148. touch $htdocs/test.php 
  149. cat >> $htdocs/test.php << CHENG 
  150. <? 
  151. phpinfo(); 
  152. ?> 
  153. CHENG 
  154.  
  155. #about phpmyadmin 
  156. cd  
  157. wget http://virtual.example.com/tar_tools/lamp/phpMyAdmin-3.4.2-all-languages.tar.gz 
  158.  
  159. tar -xzf phpMyAdmin-3.4.2-all-languages.tar.gz && mv  phpMyAdmin-3.4.2-all-languages $htdocs/phpmyadmin 
  160. cd $htdocs/phpmyadmin  
  161. #configure phpmyadmin use root nopasswd 
  162. mv config.sample.inc.php config.inc.php 
  163. sed -i '17c\$cfg['blowfish_secret'] = 'baocheng';' config.inc.php 
  164. sed -i '36c\$cfg['Servers'][$i]['AllowNoPassword'] = true;' config.inc.php 
  165.  
  166. echo "##########warning#############" >> $lamp_log 
  167. echo "Go to http://$ip/test.php" >> $lamp_log 
  168. echo "Mysql port 3306 and socket_file is  /tmp/mysql5.socket" >> $lamp_log 
  169. echo "Go to phpmyadmin http://$ip/phpmyadmin " >> $lamp_log 
  170. echo " user=root  paswd=null>> $lamp_log 
  171. echo "About selinux:disable" >> $lamp_log 
  172. echo "##########end################" >> $lamp_log  

安装脚本后,可以直接使用phpmyadmin. 在/root下有一个lamp_install.log 记录相关的信息。完成后PHP已经可以正常访问了,你需要做的就是把php文件放到/usr/local/apache2/htdocs里!

原创粉丝点击