Shell script One-click Install LNMP Menu mode installation

Source: Internet
Author: User
Tags fpm mcrypt

#!/bin/bash
#定义软件包变量
tnginx= "Nginx-1.6.0.tar.gz"
nginx= "nginx-1.6.0"
Tcmake= "Cmake-2.8.6.tar.gz"
Cmake= "cmake-2.8.6"
tlibmcrypt= "Libmcrypt-2.5.8.tar.gz"
libmcrypt= "libmcrypt-2.5.8"
tmcrypt= "Mcrypt-2.6.8.tar.gz"
mcrypt= "mcrypt-2.6.8"
Tmhash= "Mhash-0.9.9.9.tar.gz"
Mhash= "mhash-0.9.9.9"
Tmysql= "Mysql-5.5.22.tar.gz"
Mysql= "mysql-5.5.22"
tphp= "Php-5.3.28.tar.gz"
php= "php-5.3.28"
Tzen= "Zendguardloader-php-5.3-linux-glibc23-x86_64.tar.gz"
Zen= "Zendguardloader-php-5.3-linux-glibc23-x86_64"
Dir= "/usr/local"
Export path= "/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
#定义菜单函数
C () {
#根据安装目录判断软件是否已经安装
If [-D "$dir"/nginx]
Then
a=$ (echo-e "\033[32m installed \033[0m")
Else
a=$ (echo-e "\033[31m not installed \033[0m")
Fi
which CMake &>/dev/null
If [$?-eq 0]
Then
b=$ (echo-e "\033[32m installed \033[0m")
Else
b=$ (echo-e "\033[31m not installed \033[0m")
Fi
If [-D "$dir"/mysql]
Then
c=$ (echo-e "\033[32m installed \033[0m")
Else
c=$ (echo-e "\033[31m not installed \033[0m")
Fi
If [-D "$dir"/PHP5]
Then
d=$ (echo-e "\033[32m installed \033[0m")
Else
d=$ (echo-e "\033[31m not installed \033[0m")
Fi
Clear
echo "

   ||+++++++++++++++Use this script+++++++++++++++++++++||   ||===================================================||   ||+++++++++++++++服务名+++++++++++++||+++++状态++++++||         ||==================================||===============||   ||++++++++++1).NGINX Install++++++++||++++$a+++++||   ||==================================||===============||   ||++++++++++2).CMAKE Install++++++++||++++$b+++++||   ||==================================||===============||   ||++++++++++3).MySQL Install++++++++||++++$c+++++||   ||==================================||===============||   ||++++++++++4).PHP Install++++++++++||++++$d+++++||   ||===================================================||   "

Read-p "Please select the installed service [1-4]" M
}
#定义安装nginx函数
Install_nginx () {
Yum Install-y pcre-devel
If [-D "$dir"/nginx]
Then
echo "Nginx Installed"
Exit 0
Else
ID Nginx &>/dev/null
If [$?-ne 0]
Then
Useradd-m-s/sbin/nologin Nginx
Fi
if [!-F "$Tnginx"]
Then
echo "No $tnginx"
Exit 1
Else
Tar xf "$Tnginx"-C "$dir"
CD "$dir"/"$nginx"/
./configure--prefix= "$dir"/nginx--user=nginx--group=nginx--with-http_stub_status_module--with-http_ssl_module && make && make install
Ln-s "$dir"/nginx/sbin/nginx "$dir"/sbin/
Sed-i ' 9cpid logs/nginx.pid; '/usr/local/nginx/conf/nginx.conf
Fi
Fi
cd/root/
}
#定义CMAKE installation Functions
Install_cmake () {
which CMake &>/dev/null
If [$?-eq 0]
Then
echo "CMake Installed"
Exit 0
Else
if [!-F "$Tcmake"]
Then
echo "No $tcmake"
Exit 1
Else
Tar xf "$Tcmake"
CD "$cmake"
./configure && gmake && gmake Install
Fi
Fi
cd/root/
}
#定义MySQL installation Functions
Install_mysql () {
which CMake &>/dev/null
If [$?-ne 0]
Then
echo "Please install CMake first"
Exit 0
Fi
If [-D "$dir"/mysql]
Then
echo "MySQL is installed"
Exit 0
Else
if [!-F "$Tmysql"]
Then
echo "No $tmysql"
Exit 1
Else
Tar xf "$Tmysql"-C "$dir"
CD "$dir"/"$mysql"
"$dir"/bin/cmake-dcmake_install_prefix= "$dir"/mysql-dsysconfdir=/etc-ddefault_charset=utf8-ddefault_collation= Utf8_general_ci-dwith_extra_charsets=all && make && make install
CP./SUPPORT-FILES/MY-MEDIUM.CNF/ETC/MY.CNF
CP./support-files/mysql.server/etc/init.d/mysqld
chmod +x/etc/init.d/mysqld
Cp-f "$dir"/mysql/bin/"$dir"/bin/
ID MySQL
If [$?-ne 0]
Then
Useradd-m-s/sbin/nologin MySQL
Fi
Chown-r mysql.mysql "$dir"/mysql
"$dir"/mysql/scripts/mysql_install_db--datadir= "$dir"/mysql/data--basedir= "$dir"/mysql--user=mysql
/etc/init.d/mysqld start
Fi
Fi
cd/root/
}
#定义PHP安装函数
Install_php () {
If [-D "$dir"/PHP5]
Then
echo "PHP5 Installed"
Exit 0
Fi
if [!-d "$dir"/nginx-a "$dir"/mysql]
Then
echo "Please install Nginx,cmake,mysql first"
Exit 1
Else
Rpm-qa gd libxml2-devel libjpeg-devel libpng-devel &>/dev/null
If [$?-ne 0]
Then
Yum install-y gd libxml2-devel libjpeg-devel libpng-devel
Fi
if [!-F $Tphp]
Then
echo "No $tphp"
Else
Tar xf "$Tphp"-C "$dir"
CD "$dir"/"$php"
./configure--prefix= "$dir"/php5--with-gd--with-zlib--with-mysql= "$dir"/mysql--with-config-file-path= "$dir"/ PHP5--enable-mbstring--enable-fpm--with-jpeg-dir=/usr/lib && make && make install
CP./php.ini-development "$dir"/php5/php.ini
Ln-s $dir/php5/bin/
$dir/bin/
Ln-s $dir/php5/sbin/* $dir/sbin/
Fi
Fi
cd/root/
if [!-F "$Tzen"]
Then
echo "No $tzen"
Exit 1
Else
Tar xf "$Tzen"
CD "$zen"/php-5.3.x/
CP./zendguardloader.so "$dir"/php5/lib/php/
Sed-i ' $azend _extension=/usr/local/php5/lib/php/zendguardloader.so '/usr/local/php5/php.ini
Sed-i ' $azend _loader.enable=1 '/usr/local/php5/php.ini
Fi
CD "$dir"/php5/etc
CP./php-fpm.conf.default php-fpm.conf
Sed-i ' 25cpid = Run/php-fpm.pid '/usr/local/php5/etc/php-fpm.conf
Sed-i ' 140cuser = Nginx '/usr/local/php5/etc/php-fpm.conf
Sed-i ' 141cgroup = Nginx '/usr/local/php5/etc/php-fpm.conf
Sed-i ' 222cpm.start_servers = '/usr/local/php5/etc/php-fpm.conf
Sed-i ' 227cpm.min_spare_servers = 5 '/usr/local/php5/etc/php-fpm.conf
Sed-i ' 232cpm.max_spare_servers = "/usr/local/php5/etc/php-fpm.conf
Sed-i ' 217cpm.max_children = '/usr/local/php5/etc/php-fpm.conf '
/usr/local/sbin/php-fpm
Sed-i ' 65c location ~ \.php$ {'/usr/local/nginx/conf/nginx.conf
Sed-i ' 66c root html; '/usr/local/nginx/conf/nginx.conf
Sed-i ' 67c fastcgi_pass 127.0.0.1:9000; '/usr/local/nginx/conf/nginx.conf
Sed-i ' 68c fastcgi_index index.php; '/usr/local/nginx/conf/nginx.conf
Sed-i ' 69c include fastcgi.conf; '/usr/local/nginx/conf/nginx.conf
Sed-i ' 70c} '/usr/local/nginx/conf/nginx.conf
Sed-i ' 71d '/usr/local/nginx/conf/nginx.conf
#添加PHP测试页面
echo "
<?php
Phpinfo ();
?> ">/usr/local/nginx/html/index.php
/usr/local/nginx/sbin/nginx
cd/root/
}
#挂载光盘
mount/dev/sr0/media/cdrom/
#调用菜单函数
C
#判断变量是否为数字
Expr "$m" + 1 &>/dev/null
If [$?-eq 0] && [!-Z $m]
Then
#当变量符合要求时, the corresponding function is called according to the number
If [$m-eq 1]
Then
Install_nginx
If [$?-eq 0]
Then
C
If [$m-eq 2]
Then
Install_cmake
If [$?-eq 0]
Then
C
If [$m-eq 3]
Then
Install_mysql
If [$?-eq 0]
Then
C
If [$m-eq 4]
Then
install_php
If [$$-eq 0]
Then
Echo-e "\033[32mlnmp Install ok\033[0m"
Exit 0
Else
Echo-e "\033[31mlnmp Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mmysql Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mcmake Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mnginx Install false\033[0m"
Exit 1
Fi
Fi
If [$m-eq 2]
Then
Install_cmake
If [$?-eq 0]
Then
C
If [$m-eq 1]
Then
Install_nginx
If [$?-eq 0]
Then
C
If [$m-eq 3]
Then
Install_mysql
If [$?-eq 0]
Then
C
If [$m-eq 4]
Then
install_php
If [$$-eq 0]
Then
Echo-e "\033[32mlnmp Install ok\033[0m"
Exit 0
Else
Echo-e "\033[31mlnmp Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mmysql Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mnginx Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mcmake Install false\033[0m"
Exit 1
Fi
Fi
If [$m-eq 3]
Then
Install_mysql
If [$?-eq 0]
Then
C
If [$m-eq 4]
Then
install_php
If [$?-eq 0]
Then
Echo-e "\033[32mlnmp Install ok\033[0m"
Exit 0
Else
Echo-e "\033[31mlnmp Install false\033[0m"
Exit 1
Fi
Fi
Else
Echo-e "\033[31mmysql Install false\033[0m"
Exit 1
Fi
Fi
If [$m-eq 4]
Then
install_php
If [$?-eq 0]
Then
Echo-e "\033[32mlnmp Install ok\033[0m"
Exit 0
Else
Echo-e "\033[31mlnmp Install false\033[0m"
Exit 1
Fi
Fi
#当变量值不在规定的范围内会显示提示
If [$m-ne 1-o $m-ne 2-o $m-ne 3-o $m-ne 4]
Then
Echo-e "\033[31m Please enter the specified range number [1-4], do not enter other values or characters. \033[0m "
Fi
Else
Echo-e "\033[31m Please enter the specified range number [1-4], do not enter other values or characters. \033[0m "
Fi

Shell script One-click Install LNMP Menu mode installation

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.