Production server LNMP automatic installation script

Source: Internet
Author: User
Tags imagemagick mcrypt

BKJIA exclusive Article] This script has been used on production servers for more than a year and can be automatically configured on any network-based server.

Usage: save an nginx_php code file, for example, nginx_php. Upload to the server for execution.

This script is run in CentOS 5.6 i386/x86_64.

Bash nginx_php prompts, as shown in the following column.

Choose any one of the numbers according to your needs and start to install LNMP automatically.

If nginx or php has been installed before, the script will automatically check whether they have been installed. For example

The system prompts that nginx or php has been installed.

Nginx_php source code

#! /Bin/bash # author: corald powered by www.freebsdsystem.org # written by corald 2011.09.30 # version 0.1.5 build phases = "/usr/local/nginx" php52_dir = "/usr/local/php52" mysql_dir = "/usr/local /mysql "function check_init () # Check whether initialization has been executed {if ['rpm-qa | grep re2c '= "re2c-0.12.1-2.el5.x86_64"]; then echo "init already exec! "Exit 0 fi} function check_nginx () # Check whether nginx has been installed {if [-d/usr/local/nginx/]; then echo" nginx already installed! "Exit 1 fi} function check_php52 () # Check whether php has been installed {if [-d/usr/local/php52]; then echo" php 5.2.17 already installed! "Exit 1 fi} function check_mysql () # Check whether mysql has been installed {if [-d/usr/local/mysql/]; then echo-n" mysql already installed! "Exit 1 fi} function init () # system initialization {yum-y install wget gcc-c ++ autoconf bison flex re2c libmhash libjpeg-devel libpng-devel \ freetype-devel gd-devel lib2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel \ bzip2 bzip2-devel ncurses-devel curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn-devel openssl-devel echo-n" Starting download nginx_php... "cat> list <" EOF "Your imagick- 2.3.0.tgzgoogle-perftools-1.6.tar.gz fcgi. confphp. iniphp-fpmnginxdmy.cnfnginx.confphp-fpm.confEOFmkdir packages for I in 'cat list' doif [-s packages/$ I]; then echo "$ I [found]" else echo "Error: $ I not found !!! Download now ...... "wget http://www.freebsdsystem.org/linux/nginx-php/? I-P packages/fidonemv packages/nginxd/etc/init. d/mv packages/php-fpm/etc/init. d/chmod 755/etc/init. d/* chkconfig -- add nginxdchkconfig -- add php-fpmecho "create the eaccelerator directory to/data0/cache" mkdir/data0/cacheecho "create the mysql data directory to/data0/mysql/ data "mkdir-p/data0/mysql/dataecho" PATH =/usr/loca L/mysql/bin /: $ PATH ">/etc/profilesource/etc/profilegroupadd-g 80 www & useradd www-s/sbin/nologin-g www-u 80 groupadd-g 3306 mysql && useradd mysql-s/sbin/nologin-g mysql-u 3306 echo "www and mysql user & group create! "Cd packages // bin/rm-rf listecho-e" All of installed sucussful! "} Function is_version () # Is the system 64-bit or 32-bit? {If ['uname-M' = "x86_64"]; thentar zxf libunwind-0.99.tar.gztar zxvf libunwind-0.99.tar.gzcd libunwind-0.99/CFLAGS =-fPIC. /configuremake CFLAGS =-fPICmake CFLAGS =-fPIC installcd .. /else echo "your system is 32bit, not install libunwind lib! "Fi} function ins_nginx () # Install nginx {check_nginxcd packages/is_versiontar zxf google-perftools-1.6.tar.gzcd google-perftools *. /configuremakemake installcd ..tar zxf pcre-8.10.tar.gzcd pcre -*. /configure makemake install cd ..tar zxf nginx-1.0.1.tar.gzcd nginx-1.0.1. /configure -- prefix =$ {nginx_dir} -- user = www -- group = www -- with-http_stub_status_module make & make installcd .. rm-rf/usr/local/nginx/con F/nginx. confecho "/usr/local/lib">/etc/ld. so. conf. d/usr_local_lib.conf cp nginx. conf/usr/local/nginx/conf/cp fcgi. conf/usr/local/nginx/conf/echo "nginx installed sucussfully! "} Function ins_mysqlserver () # Install mysql Server {cd packages/tar zxf mysql-5.1.58.tar.gzcd mysql-5.1.58CHOST = "x86_64-pc-linux-gnu" CFLAGS = "-march = nocona-O2-pipe" CXXFLAGS = "$ {CFLAGS }". /configure -- prefix =/usr/local/mysql -- enable-validator -- 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 make & make install cp support-*/mysql. server/etc/init. d/mysqldcp my. cnf/etc/chmod 744/etc/init. d/mysqldcd/usr/local/mysqlchow N-R mysql: mysql. rm-rf SQL-mysql-tew.kdir-p/data0/mysql/relaylog/mkdir-p/data0/mysql/binlog/chown-R mysql. mysql/data0/mysql/usr/local/mysql/bin/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/data0/mysql/dataecho "mysql server 5.1.58 installed successfully! "} Function ins_mysqlclient () # Install mysql client {cd packages/tar zxf mysql-5.1.58.tar.gzcd mysql-5.1.58CHOST = "x86_64-pc-linux-gnu" CFLAGS = "-march = nocona-O2-pipe" CXXFLAGS = "$ {CFLAGS }". /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-validator "" --- Readline "" -- with-ssl "" -- enable-local-infile "" -- without-server "make & make installcd/usr/local/mysqlchown-R mysql: mysql. rm-rf SQL-your mysql-testecho "mysql client 5.1.58 installed successfully! "} Function ins_php52 () # install php {check_php52cd packages/tar zxf libiconv-1.13.1.tar.gzcd /. /configure -- prefix =/usr/localmakemake installcd .. /tar zxf autoconf-2.13.tar.gzcd autoconf-2.13. /configuire -- prefix =/usrmake & make installcd ..tar zxf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8 /. /configuremakemake install/sbin/ldconfigcd libltdl /. /configure -- enable-ltdl-installmakemake installc D .. /.. /tar zxf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9 /. /configuremakemake installcd .. /ln-s/usr/local/lib/libmcrypt. la/usr/lib/libmcrypt. la1-s/usr/local/lib/libmcrypt. so/usr/lib/libmcrypt. soln-s/usr/local/lib/libmcrypt. so.4/usr/lib/libmcrypt. so.4ln-s/usr/local/lib/libmcrypt. so.4.4.8/usr/lib/libmcrypt. so.4.4.8ln-s/usr/local/lib/libmhash. a/usr/lib/libmhash. a1-s/usr/local/lib/libmha Sh. la/usr/lib/libmhash. la1-s/usr/local/lib/libmhash. so/usr/lib/libmhash. soln-s/usr/local/lib/libmhash. so.2/usr/lib/libmhash. so.2ln-s/usr/local/lib/libmhash. so.2.0.1/usr/lib/libmhash. so.2.0.1ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-configtar zxf mcrypt-2.6.8.tar.gzcd/sbin/ldconfig. /configuremakemake installcd .. php-5.2.17.tar.gzgzip-cd php-5.2.17-f/tar zxf Pm-0.5.14.diff.gz | patch-d php-5.2.17-p1cd php-5.2.17/patch-p1-I .. /suhosin-patch-5.2.17-0.9.7.patch. /buildconf -- force. /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-sasl -- With-xmlrpc -- enable-zip -- enable-soap -- enable-suhosin -- enable-ftp make ZEND_EXTRA_LIBS = '-liconv' make installcd .. cp php. ini/usr/local/php52/etc/cp php-fpm.conf/usr/local/php52/etc/echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf. d/mysql_lib.conf/sbin/ldconfigecho "php52 installed successfully! "} Function ins_php52ext () # install php extensions {cd packages/tar zxf memcache-2.2.5.tgzcd memcache-2.2.5/$ {php52_dir}/bin/phpize. /configure -- with-php-config =$ {php52_dir}/bin/php-configmakemake installcd .. /tar jxf eaccelerator-0.9.5.3.tar.bz2cd eaccelerator-0.9.5.3 $ {php52_dir}/bin/phpize. /configure -- enable-eaccelerator = shared -- with-eaccelerator-shared-memory -- with-php-config =$ {php52_dir}/bin/php-configmakem Ake installcd .. /tar zxf ImageMagick.tar.gz cd ImageMagick-6.5.1-2 /. /configuremakemake installcd .. /tar zxf imagick-2.3.0.tgzcd imagick-2.3.0/$ {php52_dir}/bin/phpize. /configure -- with-php-config =$ {php52_dir}/bin/php-configmakemake installcd .. echo "php52 extension installed successfully! "} Cat <EOF-* The script is advocating a simple aesthetic, only one file to complete downloading, extract, configure, compile and install Nginx php mysql * -- * 1 only install nginx * -- * 2 only install nginx php * -- * 3 installation of all (include nginx php mysql) * -- * 4 only download software, no installation other * -- * 5 only install php 5.2.17 * -- * 6 only install mysql server 5.1.58 *-EOFread-p "Now select the top option to install LNMP... 1 | 2 | 3 | 4 | 5 | 6: "selectoptcase" $ selectopt "in" 1 ") init ins_nginx;" 2 ") init ins_nginx ins_mysqlclient ins_php52 ins_php52ext ;; "3") init ins_nginx ins_mysqlserver ins_php52 ins_php52ext; "4") init; "5") ins_php52 ins_php52ext; "6") ins_mysqlserver ;;*) echo "$0 nginx_php"; esac

Functions of nginx_php

No matter how nginx php and mysql are installed, if the script detection system does not execute the script, the initialization will be automatically executed, including yum installation of related components, downloading all software packages, and configuring nginx php Services)

Nginx_phpFunctions inInitInitialization:

1) install nginx php mysql components in yum

2) If packages is not found in the current directory, wget downloads the software package, configuration document, and service script to the created packages, and then deletes the Software List.

3) set nginx and php-fpm services

4) Create an eaccelerator cache directory/data0/cache, and create a mysql data DIRECTORY/data0/mysql/data

5) Add the mysql bin PATH to the system PATH.

6) create a myql group and a mysql user, www group and www user

FunctionCheck_initIndicates whether the initialization is performed.

FunctionCheck_nginxIndicates whether nginx is installed.

FunctionCheck_php52Indicates whether php has been installed.

FunctionCheck_mysqlIndicates whether mysql is installed.

FunctionIs_versionIndicates whether the system is 64-bit or 32-bit. If it is 64-bit, install the libunwind library because google-perftools uses the libunwind library in the 64-bit system, the 32-bit libunwind library does not need to be installed.

FunctionIns_nginxNginx is installed, which indicates whether the system is 64-bit, so that google-pertfools can be installed smoothly.

FunctionIns_mysqlclientIndicates installing the mysql client. This allows php to connect to the mysql server.

FunctionIns_mysqlserverIndicates installing the mysql server and setting the mysql installation directory to the mysql group and all mysql users. The mysql system library has been configured.

FunctionIns_php52Indicates installing php, including libiconv, autoconf, libmcrypt, mhash, mcrypt, and suhosin. Configure php. ini

FunctionIns_php52extIndicates installing php extensions, including mecache, eacceletator, and imagick.

Bkjia.com is an exclusive special article. For more information, see the original author and source .]

Author's profile: Cui Xiaohui's blog), the Network Name corald, the public network system administrator, proficient in website system architecture, Unix technology. Gtalk: coralzd@gmail.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.