nginx_でphp LNMP自動インストール


このスクリプトは本番サーバ上で1年以上使用されています.このスクリプトは単純な唯美を尊び、1つのスクリプトだけでネットワークのあるサーバ上でLNMPを自動的に構成できます.使用方法:chmod u+x nginx_php; ./nginx_php init|ins_mysql-server|ins_mysql-client|ins_php52|ins_php52-ext|ins_mysqlこのスクリプトは、スクリプト実行ディレクトリの下に、LNMPを保存するために必要なソフトウェアを構築します.インストールが完了すると、このディレクトリを削除できます. 
   
   
   
   
  1. #/bash  
  2. # author:coralzd powered by www.freebsdsystem.org  
  3. # written by coralzd 2011.05.05  
  4. # version 0.1.3 build 20110505  
  5.  
  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. LANG=C  
  15. yum -y install wget gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng \
  16. libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel \
  17. glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel \
  18. curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn \
  19. libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap \
  20. openldap-clients openldap-servers  
  21.  
  22. read -p "Now,will download nginxphp software...Y|y:" nginxphp  
  23.  
  24. case "$nginxphp" in   
  25.  
  26. Y|y)  
  27.  
  28. echo -n "starting download nginx_php ..." 
  29. cat > list <"EOF" &&  
  30. nginx-1.0.0.tar.gz  
  31. php-5.2.17.tar.gz  
  32. php-5.2.17-fpm-0.5.14.diff.gz  
  33. libiconv-1.13.1.tar.gz  
  34. libmcrypt-2.5.8.tar.gz  
  35. mcrypt-2.6.8.tar.gz  
  36. memcache-2.2.5.tgz  
  37. mhash-0.9.9.9.tar.gz  
  38. mysql-5.1.52.tar.gz  
  39. pcre-8.10.tar.gz  
  40. eaccelerator-0.9.6.1.tar.bz2  
  41. PDO_MYSQL-1.0.2.tgz  
  42. libunwind-0.99.tar.gz  
  43. ImageMagick.tar.gz  
  44. imagick-2.3.0.tgz  
  45. google-perftools-1.6.tar.gz  
  46. fcgi.conf  
  47. php.ini  
  48. nginx.conf  
  49. php-fpm.conf  
  50. EOF  
  51. mkdir packages  
  52. for i in `cat list`  
  53. do 
  54. if [ -s packages/$i ]; then  
  55. echo "$i [found]" 
  56. else 
  57. echo "Error: $i not found!!!download now......" 
  58. wget http://www.freebsdsystem.org/linux/nginx-php/$i -P packages/  
  59. fi  
  60. done  
  61. ;;  
  62.  
  63.  
  64. *)  
  65.  
  66. echo -n "exit install script" 
  67. exit 0  
  68. ;;  
  69.  
  70. esac   
  71.  
  72. groupadd www && useradd www -s /sbin/nologin -g www  
  73. groupadd mysql && useradd mysql -s /sbin/nologin -g mysql  
  74. echo "www and mysql user && group create!" 
  75.  
  76. /bin/rm -rf list  
  77.  
  78. echo -e "All of installed sucussful!" 
  79.  
  80.  
  81. }  
  82. function is_version()  
  83.  
  84. {  
  85.  
  86.  
  87. if [ `uname -m` == "x86_64" ];then  
  88. tar zxf libunwind-0.99.tar.gz  
  89. tar zxvf libunwind-0.99.tar.gz  
  90. cd libunwind-0.99/  
  91. CFLAGS=-fPIC ./configure  
  92. make CFLAGS=-fPIC  
  93. make CFLAGS=-fPIC install  
  94. cd ../  
  95. else 
  96.  
  97. echo "your system is 32bit ,not install libunwind lib!" 
  98. fi  
  99.  
  100.  
  101. }  
  102.  
  103. function ins_nginx()  
  104.  
  105. {  
  106.  
  107. cd packages  
  108.  
  109. is_version  
  110. tar zxf google-perftools-1.6.tar.gz  
  111. cd google-perftools-1.6  
  112. ./configure   
  113. make   
  114. make install  
  115.  
  116. cd ..  
  117. tar zxf pcre-8.10.tar.gz  
  118. cd pcre-*  
  119. ./configure   
  120. make  
  121. make install   
  122. cd ..  
  123. tar zxf nginx-1.0.0.tar.gz  
  124. cd nginx-1.0.0  
  125. ./configure --prefix=${nginx_dir} --with-google_perftools_module --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module   
  126.  
  127. make && make install  
  128. cd ..   
  129. rm -rf /usr/local/nginx/conf/nginx.conf  
  130. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf   
  131. cp nginx.conf /usr/local/nginx/conf/  
  132. cp fcgi.conf /usr/local/nginx/conf/  
  133. echo "nginx installed sucussfully!" 
  134.  
  135. }  
  136.  
  137.  
  138. function ins_mysql-server()  
  139. {  
  140.  
  141. cd packages/  
  142. tar zxf mysql-5.1.52.tar.gz  
  143. cd mysql-5.1.52  
  144. CHOST="x86_64-pc-linux-gnu" 
  145. CFLAGS="-march=nocona -O2 -pipe" 
  146. CXXFLAGS="${CFLAGS}" 
  147. ./configure "--prefix=${mysql_dir}" "--with-server-suffix=-DZWWW" "--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" "--with-plugins=partition,myisammrg" "--without-ndb-debug"   
  148.  
  149. make && make install   
  150. cp support-*/mysql.server /etc/init.d/mysqld  
  151. cd /usr/local/mysql  
  152. chown -R mysql:mysql .  
  153. rm -rf sql-bench mysql-test  
  154. echo "mysql server 5.1.52 installed successfully!" 
  155. }  
  156.  
  157.  
  158. function ins_mysql-client()  
  159. {  
  160.  
  161. cd packages/  
  162. tar zxf mysql-5.1.52.tar.gz  
  163. cd mysql-5.1.52  
  164. CHOST="x86_64-pc-linux-gnu" 
  165. CFLAGS="-march=nocona -O2 -pipe" 
  166. CXXFLAGS="${CFLAGS}" 
  167. ./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"   
  168.  
  169. make && make install  
  170. cd /usr/local/mysql  
  171. chown -R mysql:mysql .  
  172. rm -rf sql-bench mysql-test  
  173. echo "mysql client 5.1.52 installed successfully!" 
  174. }  
  175. function ins_php52()   
  176. {  
  177. cd packages/  
  178. tar zxf libiconv-1.13.1.tar.gz  
  179. cd libiconv-1.13.1/  
  180. ./configure --prefix=/usr/local  
  181. make  
  182. make install  
  183. cd ../  
  184.  
  185. tar zxf libmcrypt-2.5.8.tar.gz  
  186. cd libmcrypt-2.5.8/  
  187. ./configure  
  188. make  
  189. make install  
  190. /sbin/ldconfig  
  191. cd libltdl/  
  192. ./configure --enable-ltdl-install  
  193. make  
  194. make install  
  195. cd ../../  
  196.  
  197. tar zxf mhash-0.9.9.9.tar.gz  
  198. cd mhash-0.9.9.9/  
  199. ./configure  
  200. make  
  201. make install  
  202. cd ../  
  203.  
  204. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la  
  205. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so  
  206. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4  
  207. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8  
  208. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a  
  209. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la  
  210. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so  
  211. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2  
  212. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1  
  213. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config  
  214.  
  215. tar zxf mcrypt-2.6.8.tar.gz  
  216. cd mcrypt-2.6.8/  
  217. /sbin/ldconfig  
  218. ./configure  
  219. make  
  220. make install  
  221. cd ../  
  222.  
  223.  
  224. tar zxf php-5.2.17.tar.gz  
  225. gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1  
  226. cd php-5.2.17/  
  227. ./configure --prefix=${php52_dir} --with-config-file-path=${php52_dir}/etc --with-mysql=${mysql_dir} --with-mysqli=${mysql_dir}/bin/mysql_config --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  
  228. make ZEND_EXTRA_LIBS='-liconv' 
  229. make install  
  230. cd ..  
  231. cp php.ini /usr/local/php52/etc/  
  232. cp php-fpm.conf /usr/local/php52/etc/  
  233.  
  234. echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf  
  235. /sbin/ldconfig  
  236. echo "php52 installed successfully!" 
  237. }  
  238.  
  239. function ins_php52-ext()  
  240.  
  241. {  
  242. cd packages/  
  243.  
  244. tar zxf memcache-2.2.5.tgz  
  245. cd memcache-2.2.5/  
  246. ${php52_dir}/bin/phpize  
  247. ./configure --with-php-config=${php52_dir}/bin/php-config  
  248. make  
  249. make install  
  250. cd ../  
  251.  
  252. tar jxf eaccelerator-0.9.6.1.tar.bz2  
  253. cd eaccelerator-0.9.6.1/  
  254. ${php52_dir}/bin/phpize  
  255. ./configure --enable-eaccelerator=shared --with-php-config=${php52_dir}/bin/php-config  
  256. make  
  257. make install  
  258. cd ../  
  259.  
  260. tar zxf PDO_MYSQL-1.0.2.tgz  
  261. cd PDO_MYSQL-1.0.2/  
  262. ${php52_dir}/bin/phpize  
  263. ./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}  
  264. make  
  265. make install  
  266. cd ../  
  267.  
  268. tar zxf ImageMagick.tar.gz  
  269. cd ImageMagick-6.5.1-2/  
  270. ./configure  
  271. make  
  272. make install  
  273. cd ../  
  274.  
  275. tar zxf imagick-2.3.0.tgz  
  276. cd imagick-2.3.0/  
  277. ${php52_dir}/bin/phpize  
  278. ./configure --with-php-config=${php52_dir}/bin/php-config  
  279. make  
  280. make install  
  281. cd ../  
  282.  
  283. echo "php52 extension installed successfully!" 
  284.  
  285. }  
  286.  
  287. case $1 in   
  288.  
  289.  
  290. init)  
  291.  
  292. init   
  293. ;;  
  294. ins_mysql-server)  
  295.  
  296. ins_mysql-server  
  297.  
  298. ;;  
  299. ins_mysql-client)  
  300. ins_mysql-client  
  301. ;;  
  302. ins_nginx)  
  303. ins_nginx   
  304. ;;  
  305. ins_php52)  
  306. ins_php52   
  307. ;;  
  308. ins_php52-ext)  
  309. ins_php52-ext  
  310. ;;  
  311. *)  
  312.  
  313. echo "Usage:`basename $0` {init|ins_mysql-server|ins_mysql-client|ins_php52|ins_php52-ext|ins_mysql}" 
  314. ;;  
  315. esac  
  316.