LNMP Shell Installation Script

Source: Internet
Author: User
Tags addgroup fpm install php

LNMP stands for: Linux system nginx+mysql+php this site server architecture. LNMP is now the most large companies in the Web environment, Nginx Small and efficient Web server and reverse proxy server, compared to Apach occupies less resources, more anti-concurrency force, and processing the static file speed very fast. MySQL is a small-scale relational database management system. PHP is an HTML-embedded language that is a scripting language for embedded HTML documents executed on the server side. These four kinds of software are free software, combined to become a free, efficient website service system. Close to the new year, the author at home busy writing a lnmp shell installation script, the author is now a novice in school learning, there can be optimized places, I hope you can put forward, thank you.

#!/bin/bashclear Cat << EOF Welcome to Ike LNMP install system!!!                    (^*^) 1) Install Nginx 2) install PHP 3) install MySQL 4) Install Nginx and PHP 5) install LNMP (Linux nginx,mysql,php) eofecho-n "Please enter (1 -5): "Read Enterclear#install pcredownloadpcre= ' wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ Pcre-8.41.tar.gz ' tarpcre1= ' tar-zvxf pcre-8.41.tar.gz ' cdpcredir= ' cd pcre-8.41 ' install2= './configure ' install3= ' Make ' install4= ' make install ' cplibpcre= ' cp/usr/local/lib/libpcre.so.1/lib/libpcre.so.1 ' addgroup= ' Groupadd www ' adduser= ' useradd-s/bin/false www ' adddir= ' mkdir/usr/local/nginx ' httpdstop= ' service httpd stop ' addlogdir= ' mkdir/ Data0/logs/nginx ' dirmod= ' chown www:www/data0/logs/nginx-r ' #install nginxdownloadnginx= ' wget http://nginx.org/ Download/nginx-1.8.1.tar.gz ' sec= ' tar-zvxf nginx-1.8.1.tar.gz ' then0= ' cd nginx-1.8.1 ' then1= './configure--User=www--group=www--prefix=/usr/local/nginx ' nginxinstall= ' make ' nginxinstall2= ' make install ' setnginx1= ' sed-i ' s/ \/scripts/$document _root/g "/usr/local/nginx/conf/nginx.conf ' startnginx1= '/usr/local/nginx/sbin/nginx ' Installnginx () {$zlib $downloadpcre$tarpcre1$cdpcredir$install2$install3$install4$cplibpcre$addgroup$adduser$ adddir$addlogdir$httpdstop$dirmod$downloadnginx$sec$then0$then1$nginxinstall$nginxinstall2$setnginx1$ Startnginx1}installmysql () {rm-rf/etc/my.cnftouch/etc/my.cnfcat >>/etc/my.cnf << Eof[mysqld] Character-set-server = Utf8mb4default_storage_engine = Innodblog_timestamps = systemsocket=/tmp/mysql.sockbasedir=/ Usr/local/mysql Datadir=/usr/local/mysql/data max_connections = 1000max_connect_errors = 1000table_open_cache = 1024max_allowed_packet = 128mopen_files_limit = 65535explicit_defaults_for_timestamp=true[mysqld_safe]pid-file=/        usr/local/mysql/data/fzjh.pid[log]log-error=/usr/local/mysql/log/error.logeof if [$ (uname-p) = = x86_64] Then wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz tar-zvxf mysql-5.7. 20-linux-glibc2.12-x86_64.tar.gz MV Mysql-5.7.20-linux-glibc2.12-x86_64/usr/local/mysql RM-RF mysql-5.7.2 0-linux-glibc2.12-x86_64.tar.gz Else wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc 2.12-i686.tar.gz tar-zvxf mysql-5.7.20-linux-glibc2.12-i686.tar.gz MV mysql-5.7.20-linux-glibc2.12-i686/u Sr/local/mysql rm-rf mysql-5.7.20-linux-glibc2.12-i686.tar.gz fiaddmysqluser= ' useradd mysql-s/sbin/nologin ' cr Eatedatadir= ' mkdir/usr/local/mysql/data ' installmysql= '/usr/local/mysql/bin/mysql_install_db--user=mysql-- Basedir=/usr/local/mysql--datadir=/usr/local/mysql/data ' startmysql= '/usr/local/mysql/support-files/ Mysql.server Restart ' $addmysqluser $createdatadir$installmysql$startmysqldbpasswd=$ (Cat/root/.mysql_secret | grep- V ' # ')/usr/local/mysql/bin/mysql-uroot-p$dbpasswd << EOF ALter user ' root ' @ ' localhost ' identified by ' 123456 ' EOF} #installphpdownloadphp = ' wget http://au1.php.net/get/ Php-7.1.10.tar.gz/from/this/mirror-o php-7.1.10.tar.gz ' tarphp= ' tar-zvxf php-7.1.10.tar.gz ' gophpdir= ' CD php-7.1.10 ' maketest= ' make ' makeinstall= ' make install ' set1= ' mv/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/ Php-fpm.conf ' set2= ' mv/usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf ' set3= ' MV Php.ini-development/usr/local/php/bin/php.ini ' Chajian () {if [$ (Rpm-qa | grep libxml2-devel | wc-l)! = 0];thenecho L IBXML2 Libxml2-devel is Installedelseyum install LIBXML2 libxml2-devel-yfiif [$ (Rpm-qa | grep curl-devel | wc-l)! = 0 ];then echo Curl-devel is installedelse yum install-y curl-develfiif [$ (Rpm-qa | grep wget | wc-l)! = 0]then If [$ (R Pm-qa | grep gcc-c++ | WC-L)! = 0];thenecho "wget and GCC gcc-c++ is installed" Elseyum install-y gcc gcc-c++fielse yum install-y wget fiif [ $ (Rpm-qa | grep zlib-devel | wc-l)! =0];then echo "Zlib-devel is install" Else Yum install-y zlib-develfi}installphp () {$downloadphp $tarphp$gophpdirif [ent ER = = 5] then./configure--prefix=/usr/local/php--enable-fpm--with-curl--with-mysql=/usr/local/mysql--with-pdo-mys QL else./configure--prefix=/usr/local/php--enable-fpm--with-curl fi$maketest$makeinstall$set1$set2$set3}case $ Enter in1) Chajianinstallnginxclearecho ' Nginx File:/usr/local/nginx ' echo ' html file:/usr/local/nginx/html ';; 2) Chajianinstallphpclearecho ' php file:/usr/local/php ';; 3) Chajianinstallmysqlclearecho ' MySQL file:=/usr/local/mysql ' echo ' Mysql_user:root ' echo you mysql_password:$ DBPASSWD;; 4) Chajianinstallnginxinstallphpclearecho ' Nginx File:/usr/local/nginx ' echo ' HTML file:/usr/local/nginx/html ' echo ' PHP file:/usr/local/php ';; 5) Chajianinstallnginxinstallmysqlinstallphpclearecho ' Nginx File:/usr/local/nginx ' echo ' HTML File:/usr/local/nginx /html ' echo ' php file:/usr/local/php ' echo ' mysql file:=/usr/local/mysql ' echo ' You Mysql_user:root ' ECho you Mysql_password: $dbpasswd ESAC 

The next step is to explain the script code

clearcat << EOF                 Welcome to Ahui install system!!!(^*^)                    1) Install nginx                    2) Install php                    3) Install mysql                    4) Install nginx and php                    5) Install lnmp(linux nginx,mysql,php)EOFecho -n "Please you enter (1-5):"  read  enter

First, use EOF to print the interface we want to display to cat, and then use read to read an input variable to enter the variable.

#install pcredownloadpcre= ' wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz ' tarpcre1= ' Tar-zvxf pcre-8.41.tar.gz ' cdpcredir= ' cd pcre-8.41 ' install2= './configure ' install3= ' make ' install4= ' make install ' Cplibpcre= ' cp/usr/local/lib/libpcre.so.1/lib/libpcre.so.1 ' addgroup= ' groupadd www ' adduser= ' useradd-s/bin/false www ' adddir= ' mkdir/usr/local/nginx ' httpdstop= ' service httpd stop ' addlogdir= ' Mkdir/data0/logs/nginx ' dirmod= ' chown Www:www/data0/logs/nginx-r ' #install nginxdownloadnginx= ' wget http://nginx.org/download/nginx-1.8.1.tar.gz ' sec= ' TAR-ZVXF nginx-1.8.1.tar.gz ' then0= ' cd nginx-1.8.1 ' then1= './configure--user=www--group=www--prefix=/usr/local/ Nginx ' nginxinstall= ' make ' nginxinstall2= ' make install ' setnginx1= ' sed-i ' s/\/scripts/$document _root/g '/usr/local/ Nginx/conf/nginx.conf ' startnginx1= '/usr/local/nginx/sbin/nginx ' Installnginx () {$zlib $downloadpcre$tarpcre1$ Cdpcredir$install2$install3$install4$cplibpcre$addgroup$adduser$adddir$addlogdir$httpdstop$dirmod$downlOADNGINX$SEC$THEN0$THEN1$NGINXINSTALL$NGINXINSTALL2$SETNGINX1$STARTNGINX1} 

We will install Nginx required Pcre First compile the installation, define the variable name, directly with the $ plus variable name, the use of these commands on the line, and then install Nginx.

Installmysql () {rm-rf/etc/my.cnftouch/etc/my.cnfcat >>/etc/my.cnf << eof[mysqld]character-set-server = Utf8mb4default_storage_engine = Innodblog_timestamps = Systemsocket=/tmp/mysql.sockbasedir=/usr/local/mysql DataDir =/usr/local/mysql/data max_connections = 1000max_connect_errors = 1000table_open_cache = 1024max_allowed_packet = 128mopen_files_limit = 65535explicit_defaults_for_timestamp=true[mysqld_safe]pid-file=/usr/local/mysql/data/ fzjh.pid[log]log-error=/usr/local/mysql/log/error.logeof if [$ (uname-p) = = x86_64] then wget https:// Dev.mysql.com/get/downloads/mysql-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz TAR-ZVXF mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz mv Mysql-5.7.20-linux-glibc2.12-x86_64/usr/local/mysql RM-RF m ysql-5.7.20-linux-glibc2.12-x86_64.tar.gz Else wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-l inux-glibc2.12-i686.tar.gz TAR-ZVXF Mysql-5.7.20-linux-glibc2.12-i686.tar. GZ MV Mysql-5.7.20-linux-glibc2.12-i686/usr/local/mysql RM-RF mysql-5.7.20-linux-glibc2.12-i686.tar.gz Fiaddmysqluser= ' useradd mysql-s/sbin/nologin ' createdatadir= ' mkdir/usr/local/mysql/data ' installmysql= '/usr/local /mysql/bin/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data ' startmysql= '/ Usr/local/mysql/support-files/mysql.server Restart ' $addmysqluser $createdatadir$installmysql$startmysqldbpasswd= $ (Cat/root/.mysql_secret | grep-v ' # ')}

Then MySQL, first delete the my.cnf inside the system, use touch plus eof to create our own my.cnf, and then use UNAME-P to detect how many bits of our system are downloading the appropriate MySQL installation package.

chajian(){if [ $(rpm -qa | grep libxml2-devel | wc -l) != 0 ];thenecho libxml2 libxml2-devel is installedelseyum install libxml2 libxml2-devel -yfiif [ $(rpm -qa | grep curl-devel | wc -l) != 0 ];then echo curl-devel is installedelse yum install -y curl-develfiif [ $(rpm -qa | grep wget | wc -l) != 0 ]then if [ $(rpm -qa | grep gcc-c++ | wc -l) != 0 ];thenecho "wget and gcc gcc-c++ is installed"elseyum install -y gcc gcc-c++fielse yum install -y wget fiif [ $(rpm -qa | grep zlib-devel | wc -l) != 0 ];then  echo  "zlib-devel is install"else  yum install -y zlib-develfi

PS: These are the use if statements to detect some of the packages to be dependent

#installphpdownloadphp=‘wget http://au1.php.net/get/php-7.1.10.tar.gz/from/this/mirror -O php-7.1.10.tar.gz‘tarphp=‘tar -zvxf php-7.1.10.tar.gz‘gophpdir=‘cd php-7.1.10‘maketest=‘make‘makeinstall=‘make install‘set1=‘mv /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf  ‘set2=‘mv /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf‘set3=‘mv php.ini-development /usr/local/php/bin/php.ini‘installphp(){$downloadphp$tarphp$gophpdirif [ enter == 5 ]    then./configure --prefix=/usr/local/php --enable-fpm --with-curl --with-mysql=/usr/local/mysql --with-pdo-mysql    else./configure --prefix=/usr/local/php --enable-fpm --with-curl fi$maketest$makeinstall$set1$set2$set3}

This is the PHP installation method, and the above several similar. I think a stake in the installation of LNMP must use Pod-mysql to make MySQL and PHP can be linked together.

case $enter in1)chajianinstallnginxclearecho ‘nginx file:/usr/local/nginx‘echo ‘html file:/usr/local/nginx/html‘;;2)chajianinstallphpclearecho ‘php file:/usr/local/php‘;;3)chajianinstallmysqlclearecho ‘mysql file:=/usr/local/mysql‘echo ‘you mysql_user:root‘echo  you mysql_password:$dbpasswd ;;4)chajianinstallnginxinstallphpclearecho ‘nginx file:/usr/local/nginx‘echo ‘html file:/usr/local/nginx/html‘echo ‘php file:/usr/local/php‘;;5)chajianinstallnginxinstallmysqlinstallphpclearecho ‘nginx file:/usr/local/nginx‘echo ‘html file:/usr/local/nginx/html‘echo ‘php file:/usr/local/php‘echo ‘mysql file:=/usr/local/mysql‘echo ‘you mysql_user:root‘echo  you mysql_password:$dbpasswd esac

Finally, use case multiple selection to enter the value entered by the Enter variable, according to the case to do the corresponding installation.
Finally, thank you for your reading, I hope you can optimize the place put forward to learn from each other.

LNMP Shell Installation Script

Related Article

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.