用nginx_php 自動安裝LNMP第二版

本次腳本修正第一版存在的錯誤,並更新了軟件包版本,php 增加suhosin等等,命令參數有了改變. sh nginx_php init|ins_nginx|ins_mysqlserver|ins_mysqlclient|ins_php52|ins_php52ext

  1. #!/bin/bash  
  2. # author:coralzd powered by www.freebsdsystem.org  
  3. # written by coralzd 2010.11.05  
  4. # version 0.1.4 build 20110831  
  5. # description: nginx php mysql install shell  
  6.  
  7. nginx_dir="/usr/local/nginx" 
  8. php52_dir="/usr/local/php52" 
  9. mysql_dir="/usr/local/mysql" 
  10.  
  11. function init()   
  12. {  
  13.  
  14. yum -y install wget gcc gcc-c++ autoconf bison flex re2c  libmhash libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  
  15.  
  16. read -p "Now,will download nginxphp software...Y|y:"  nginxphp  
  17.  
  18. case "$nginxphp" in   
  19.  
  20.      Y|y)  
  21.  
  22. echo -n "starting download nginx_php ..." 
  23. cat > list << "EOF" &&  
  24. nginx-1.0.1.tar.gz  
  25. php-5.2.17.tar.gz  
  26. php-5.2.17-fpm-0.5.14.diff.gz  
  27. libiconv-1.13.1.tar.gz  
  28. libmcrypt-2.5.8.tar.gz  
  29. mcrypt-2.6.8.tar.gz  
  30. memcache-2.2.5.tgz 
  31. mhash-0.9.9.9.tar.gz  
  32. mysql-5.1.58.tar.gz  
  33. suhosin-patch-5.2.17-0.9.7.patch 
  34. pcre-8.10.tar.gz  
  35. autoconf-2.13.tar.gz  
  36. eaccelerator-0.9.5.3.tar.bz2  
  37. PDO_MYSQL-1.0.2.tgz 
  38. libunwind-0.99.tar.gz  
  39. ImageMagick.tar.gz  
  40. imagick-2.3.0.tgz 
  41. google-perftools-1.6.tar.gz  
  42. fcgi.conf  
  43. php.ini  
  44. my.cnf  
  45. nginx.conf  
  46. php-fpm.conf  
  47. EOF  
  48. mkdir packages  
  49.         for i in `cat list`  
  50. do  
  51. if [ -s packages/$i ]; then  
  52.   echo "$i [found]" 
  53. else 
  54.   echo "Error: $i not found!!!download now......" 
  55.   wget http://www.freebsdsystem.org/linux/nginx-php/$i -P packages/  
  56. fi  
  57. wget http://www.freebsdsystem.org/linux/nginx-php/nginxd  
  58. wget http://www.freebsdsystem.org/linux/nginx-php/php-fpm  
  59. mv nginxd /etc/init.d/  
  60. mv php-fpm /etc/init.d/  
  61. chmod 755 /etc/init.d/*  
  62. chkconfig --add nginxd  
  63. chkconfig --add php-fpm  
  64. echo "create the eaccelerator directory to /data0/cache" 
  65. mkdir /data0/cache  
  66. echo "create the mysql data directory to /data0/mysql/data" 
  67. mkdir -p /data0/mysql/data  
  68. echo "PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile  
  69. source  /etc/profile  
  70. done  
  71. ;;  
  72.  
  73. *)  
  74.  
  75.   echo -n "exit install script" 
  76.    exit 0 
  77. ;;  
  78.  
  79. esac    
  80.  
  81. groupadd www &&  useradd www -s /sbin/nologin -g www  
  82. groupadd mysql && useradd mysql -s /sbin/nologin -g mysql  
  83. echo "www and mysql user && group create!" 
  84. cd packages/  
  85. tar zxf   
  86. /bin/rm -rf list  
  87.  
  88. echo -e "All of installed sucussful!" 
  89.  
  90.  
  91. }  
  92. function is_version()  
  93.  
  94. {  
  95.  
  96.       
  97. if [ `uname -m` == "x86_64" ];then  
  98. tar zxf libunwind-0.99.tar.gz  
  99. tar zxvf libunwind-0.99.tar.gz  
  100. cd libunwind-0.99/  
  101. CFLAGS=-fPIC ./configure  
  102. make CFLAGS=-fPIC  
  103. make CFLAGS=-fPIC install  
  104. cd ../  
  105. else 
  106.  
  107.         echo "your system is 32bit ,not install libunwind lib!" 
  108. fi  
  109.  
  110.  
  111. }  
  112.  
  113. function ins_nginx()  
  114.  
  115. {  
  116.  
  117. cd packages/  
  118. is_version  
  119. tar zxf google-perftools-1.6.tar.gz  
  120. cd google-perftools*  
  121. ./configure  
  122. make  
  123. make install  
  124. cd ..  
  125.  
  126. tar zxf pcre-8.10.tar.gz  
  127. cd pcre-*  
  128. ./configure   
  129. make  
  130. make install   
  131. cd ..  
  132. tar zxf nginx-1.0.1.tar.gz  
  133. cd nginx-1.0.1 
  134. ./configure --prefix=${nginx_dir} --user=www --group=www --with-http_stub_status_module     
  135.  
  136. make && make install  
  137. cd ..   
  138. rm -rf /usr/local/nginx/conf/nginx.conf  
  139. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf   
  140. cp nginx.conf /usr/local/nginx/conf/  
  141. cp fcgi.conf /usr/local/nginx/conf/  
  142. echo "nginx installed sucussfully!" 
  143. }  
  144.  
  145. function ins_mysqlserver()  
  146. {  
  147.  
  148. cd packages/  
  149. tar zxf mysql-5.1.58.tar.gz  
  150. cd mysql-5.1.58 
  151. CHOST="x86_64-pc-linux-gnu" 
  152. CFLAGS="-march=nocona -O2 -pipe" 
  153. CXXFLAGS="${CFLAGS}" 
  154. ./configure --prefix=/usr/local/mysql --enable-assembler --with-server-suffix=-DZWWW --enable-thread-safe-client --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8 --with-client-ldflags=-all-static --with-collation=utf8_general_ci --with-extra-charsets=all --with-mysqld-ldflags=-all-static --with-mysqld-ldflags=-ltcmalloc  --with-mysqld-user=mysql --with-plugins=partition,myisammrg --with-pthread --with-unix-socket-path=/tmp/mysql.sock --without-ndb-debug   
  155. make && make install   
  156. cp support-*/mysql.server /etc/init.d/mysqld  
  157. cp my.cnf /etc/  
  158. chmod 744 /etc/init.d/mysqld  
  159. cd /usr/local/mysql  
  160.  
  161. chown -R mysql:mysql .  
  162. rm -rf sql-bench mysql-test  
  163. mkdir -p /data0/mysql/relaylog/  
  164. mkdir -p /data0/mysql/binlog/  
  165. chown -R mysql.mysql /data0/mysql  
  166.  
  167. /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data0/mysql/data  
  168. echo "mysql server  5.1.58 installed successfully!" 
  169. }  
  170.  
  171. function ins_mysqlclient()  
  172. {  
  173.  
  174. cd packages/  
  175. tar zxf mysql-5.1.58.tar.gz  
  176. cd mysql-5.1.58 
  177. CHOST="x86_64-pc-linux-gnu" 
  178. CFLAGS="-march=nocona -O2 -pipe" 
  179. CXXFLAGS="${CFLAGS}" 
  180. ./configure "--prefix=${mysql_dir}"   "--with-mysqld-user=mysql"   "--without-debug" "--with-charset=utf8"  "--with-extra-charsets=all"  "--with-pthread" "--with-big-tables" "--enable-thread-safe-client" "--enable-assembler" "--with-readline" "--with-ssl" "--enable-local-infile"  "--without-server"   
  181.  
  182. make && make install  
  183. cd /usr/local/mysql  
  184. chown -R mysql:mysql .  
  185. rm -rf sql-bench mysql-test  
  186. echo "mysql client  5.1.58 installed successfully!" 
  187. }  
  188. function ins_php52()          
  189. {  
  190. cd packages/  
  191. tar zxf libiconv-1.13.1.tar.gz  
  192. cd libiconv-1.13.1/  
  193. ./configure --prefix=/usr/local  
  194. make  
  195. make install  
  196. cd ../  
  197.  
  198. tar zxf autoconf-2.13.tar.gz  
  199. cd autoconf-2.13 
  200. ./configuire --prefix=/usr  
  201. make && make install  
  202. cd ..  
  203.  
  204. tar zxf libmcrypt-2.5.8.tar.gz  
  205. cd libmcrypt-2.5.8/  
  206. ./configure  
  207. make  
  208. make install  
  209. /sbin/ldconfig  
  210. cd libltdl/  
  211. ./configure --enable-ltdl-install  
  212. make  
  213. make install  
  214. cd ../../  
  215.  
  216. tar zxf mhash-0.9.9.9.tar.gz  
  217. cd mhash-0.9.9.9/  
  218. ./configure  
  219. make  
  220. make install  
  221. cd ../  
  222.  
  223. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la  
  224. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so  
  225. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 
  226. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 
  227. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a  
  228. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la  
  229. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so  
  230. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 
  231. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 
  232. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config  
  233.  
  234. tar zxf mcrypt-2.6.8.tar.gz  
  235. cd mcrypt-2.6.8/  
  236. /sbin/ldconfig  
  237. ./configure  
  238. make  
  239. make install  
  240. cd ../  
  241.  
  242.  
  243. tar zxf php-5.2.17.tar.gz  
  244. gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1  
  245. cd php-5.2.17/  
  246. patch -p1 -i ../suhosin-patch-5.2.17-0.9.7.patch 
  247. ./buildconf --force    
  248. ./configure --prefix=${php52_dir} --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=${php52_dir}/etc  --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-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-suhosin --enable-ftp   
  249. make ZEND_EXTRA_LIBS='-liconv' 
  250. make install  
  251. cd ..  
  252. cp php.ini /usr/local/php52/etc/  
  253. cp php-fpm.conf /usr/local/php52/etc/  
  254.  
  255. echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf  
  256. /sbin/ldconfig  
  257. echo "php52 installed successfully!" 
  258. }  
  259.  
  260. function ins_php52ext()  
  261.  
  262. {  
  263. cd packages/  
  264.  
  265. tar zxf memcache-2.2.5.tgz 
  266. cd memcache-2.2.5/  
  267. ${php52_dir}/bin/phpize  
  268. ./configure --with-php-config=${php52_dir}/bin/php-config  
  269. make  
  270. make install  
  271. cd ../  
  272.  
  273. tar jxf eaccelerator-0.9.5.3.tar.bz2  
  274. cd eaccelerator-0.9.5.3 
  275. ${php52_dir}/bin/phpize  
  276. ./configure --enable-eaccelerator=shared --with-eaccelerator-shared-memory --with-php-config=${php52_dir}/bin/php-config  
  277. make  
  278. make install  
  279. cd ../  
  280.  
  281. #tar zxf PDO_MYSQL-1.0.2.tgz  
  282. #cd PDO_MYSQL-1.0.2/  
  283. #${php52_dir}/bin/phpize  
  284. #./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}  
  285. #make  
  286. #make install  
  287. #cd ../  
  288.  
  289. tar zxf ImageMagick.tar.gz  
  290. cd ImageMagick-6.5.1-2/  
  291. ./configure  
  292. make  
  293. make install  
  294. cd ../  
  295.  
  296. tar zxf imagick-2.3.0.tgz 
  297. cd imagick-2.3.0/  
  298. ${php52_dir}/bin/phpize  
  299. ./configure --with-php-config=${php52_dir}/bin/php-config  
  300. make  
  301. make install  
  302. cd ..  
  303.  
  304.  
  305. echo "php52 extension installed successfully!" 
  306.  
  307.  
  308. }  
  309.  
  310. case $1 in   
  311.  
  312.  
  313. init)  
  314.  
  315.         init   
  316.          ;;  
  317. ins_mysqlserver)  
  318.            
  319.           ins_mysqlserver  
  320.  
  321.           ;;  
  322. ins_mysqlclient)  
  323.           ins_mysqlclient  
  324.           ;;  
  325. ins_nginx)  
  326.            ins_nginx   
  327.            ;;  
  328. ins_php52)  
  329.        ins_php52    
  330.            ;;  
  331. ins_php52ext)  
  332.        ins_php52ext  
  333.        ;;  
  334. *)  
  335.  
  336.      echo "Usage:`basename $0` {init|ins_mysqlserver|ins_mysqlclient|ins_php52|ins_php52ext}" 
  337.          ;;  
  338. esac 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章