资讯专栏INFORMATION COLUMN

Centos7下一键安装LNMP环境脚本

FullStackDeveloper / 1873人阅读

摘要:

#!/bin/bash
read -p "The installation process takes about 5 to 10 minutes, depending on the performance of your server. To confirm the installation of the lnmp environment, press the Enter key."
function red(){
    echo -e "	33[31m$133[0m"
}
function green(){
    echo -e "	33[32m$133[0m"
}
yum clean all &> /dev/null
yum -y install epel-release  &> /dev/null
while :
do
    cat /etc/ld.so.conf | grep lib64 &> /dev/null 
    if [ $? -ne 0 ];then
        echo  """/usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64""" >> /etc/ld.so.conf
        ldconfig -v &> /dev/null
    fi
        libzip_stat=`rpm -qa |grep libzip &> /dev/null && echo "yes" || echo "no"`
        mariadb_stat=`rpm -qa |grep mariadb &> /dev/null && echo "yes" || echo "no"`
    yum_stat=`yum repolist |tail -1 |awk "{print $2}"`
        if [ $libzip_stat = yes ];then
                rpm -e --nodeps `rpm -qa | grep libzip`
        continue
        elif [ $mariadb_stat = yes ];then
                rpm -e --nodeps `rpm -qa | grep mariadb`
        continue
    elif [ $yum_stat = 0 ];then
        red "Yum error,Check your yum source!!!(maybe network,yum configure...)"
        exit
    else
            echo -e "33[05m33[35mStart testing the environment...33[0m"
        echo -e "	33[32mStart testing the environment...   [ OK ]33[0m"
        break
    fi        
done
function need_rpm()
{
    yum -y install make
    yum -y install gmake 
    yum -y install gcc
    yum -y install gcc-c++
    yum -y install wget
    yum -y install openssl
    yum -y install openssl-devel
    yum -y install curl
    yum -y install curl-devel
    yum -y install libjpeg
    yum -y install libjpeg-devel
    yum -y install libpng
    yum -y install libpng-devel
    yum -y install freetype
    yum -y install freetype-devel
    yum -y install pcre
    yum -y install pcre-devel
    yum -y install libxslt
    yum -y install libxslt-devel
    yum -y install bzip2
    yum -y install bzip2-devel
    yum -y install libxml2
    yum -y install libxml2-devel
}
function down_app()
{
        wget -P /lnmp/ https://nginx.org/download/nginx-1.14.2.tar.gz   &> /dev/null && echo -e "	33[32mNginx Download completed!33[0m" || echo -e "	33[31mNginx Download Faild!33[0m"
        wget -P /lnmp/ http://cn2.php.net/get/php-7.3.0.tar.gz/from/this/mirror   &> /dev/null && echo -e "	33[32mPHP Download completed!33[0m" || echo -e "	33[31mPHP Download Faild!33[0m"  
        wget -P /lnmp/ https://nih.at/libzip/libzip-1.2.0.tar.gz   &> /dev/null && echo -e "	33[32mLibzip Download completed!33[0m" ||  echo -e "	33[31mLibzip Download Faild!33[0m"
    wget -P /lnmp/ https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz    &> /dev/null && green "Mysql Download completed!" || red "Mysql Download Faild!"
}

function nginx_install_configure()
{
    id nginx &> /dev/null && userdel nginx
    useradd -M -s /sbin/nologin nginx &>/dev/null
    cd /lnmp / && tar -xf nginx-1.14.2.tar.gz && cd nginx-1.14.2/    
    ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream &>> /tmp/.nginx.configure.log
    if [ $? -ne 0 ];then
        red "Nginx configure error!!! See /tmp/.nginx.configure.log" 
        exit
    else
        echo """ Configuration summary:
              nginx path prefix: "/usr/local/nginx"
               nginx binary file: "/usr/local/nginx/sbin/nginx"
               nginx modules path: "/usr/local/nginx/modules"
               nginx configuration prefix: "/usr/local/nginx/conf"
               nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
               nginx pid file: "/usr/local/nginx/logs/nginx.pid"
               nginx error log file: "/usr/local/nginx/logs/error.log"
               nginx http access log file: "/usr/local/nginx/logs/access.log"
               nginx http client request body temporary files: "client_body_temp"
               nginx http proxy temporary files: "proxy_temp"
               nginx http fastcgi temporary files: "fastcgi_temp"
               nginx http uwsgi temporary files: "uwsgi_temp"
               nginx http scgi temporary files: "scgi_temp"
            """
    fi
    make &>> /tmp/.nginx.make.log
    if [ $? -ne 0 ];then
        red "Nginx make error!!! See /tmp/.nginx.make.log"
    fi
    make install &>> /tmp/.nginx.makeinstall.log
    if [ $? -ne 0 ];then
        red "Nginx make install error!!! See /tmp/.nginx.makeinstall.log"
    fi    

    cd /usr/local/nginx/
    cp -p conf/nginx.conf conf/nginx.conf.bak
    sed -i "65,68s/#//g" conf/nginx.conf
    sed -i "70,71s/#//g" conf/nginx.conf
    sed -i "s/fastcgi_params/fastcgi.conf/g" conf/nginx.conf
    
    green "Nginx installed and configure successful."
    /usr/local/nginx/sbin/nginx -t &> /dev/null && /usr/local/nginx/sbin/nginx
    netstat -nutlp |grep 80 &> /dev/null
    if [ $? -ne 0 ];then
        red "Nginx start error!!!"
    else
        green "Nginx started."
    fi
}


function mysql_install_configure()
{
        id mysql &> /dev/null && userdel mysql
        useradd -M -s /sbin/nologin mysql &> /dev/null
        cd /lnmp/
        tar -xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
        mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
        cd /usr/local/mysql/
        mkdir data && chown -R mysql:mysql /usr/local/mysql/
        ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize &>> /tmp/.mysql.initialize.log
        if [ $? -ne 0 ];then
                red "Mysql initialize error!!! See /tmp/.mysql.initialize.log"
    else
        pass=`tail -1 /tmp/.mysql.initialize.log | awk "{print $NF}"`
        green "Mysql initialize successful.)"
        green  "Initial password: $pass"
        echo """ Configuration summary:
              Mysql path prefix: "/usr/local/mysql"
              Mysql data path: "/usr/local/mysql/data"
            """
        fi
        ./support-files/mysql.server start &>> /tmp/.mysql.start.log
        netstat -nutlp | grep mysql &> /dev/null
        if [ $? -ne 0 ];then
                red  "Mysql start error!!! See /tmp/.mysql.start.log"
        else
                green  "Mysql started."
        fi
}


function libzip_install_configure()
{
    cd /lnmp/
    tar -xf libzip-1.2.0.tar.gz
    cd libzip-1.2.0
    ./configure &> /dev/null
    make    &> /dev/null
    make install    &> /dev/null
    cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
    green "Libzip installed."
}


function php_install_configure()
{
        cd /lnmp/
        tar -xf mirror
        cd  php-7.3.0/
        while :
        do
                ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip  &>> /tmp/.php.configure.log
                if [ $? -ne 0 ];then
                        red "PHP configure error!!! See /tmp/.php.configure.log"
                           exit 
                else
                        green "PHP configure is ok"
                   while :
                   do
                           make  &>> /tmp/.php.make.log
                           if [ $? -ne 0 ];then
                                   red "PHP make error!!! See /tmp/.php.make.log"
                                      exit 
                           else
                                   green "PHP make is ok"
                        while :
                        do
                        cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
                                make install &>> /tmp/.php.makeinstall.log
                                if [ $? -ne 0 ];then
                                        red "PHP makeinstall error!!! See /tmp/.php.makeinstall.log"
                            exit
                                else
                                        green "PHP Installed."
                            break
                                fi
                        done
                    break
                           fi
                   done
            break
                fi
        done

        cp php.ini-development /usr/local/php/lib/php.ini
        cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
        cp sapi/fpm/php-fpm /usr/local/bin
        sed -i "s/; cgi.fix_pathinfo=1/ cgi.fix_pathinfo=0/g" /usr/local/php/lib/php.ini
        groupadd www-data &> /dev/null
        useradd -g www-data www-data &> /dev/null
        cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
        sed -i "s/user = nobody/user = www-data/g" /usr/local/php/etc/php-fpm.d/www.conf
        sed -i "s/group = nobody/group = www-data/g" /usr/local/php/etc/php-fpm.d/www.conf
        /usr/local/bin/php-fpm
        netstat -nutlp |grep 9000
        if [ $? -ne 0 ];then
                red "PHP-FPM start error!!!"
        else
                green "PHP-FPM started"
        fi
}




#start execute
echo -e "33[05m33[35mInstall dependent software...33[0m"
need_rpm &> /dev/null
green "Install dependent software...		[ OK ]" 
echo -e "33[05m33[35mStart download apps...33[0m"
down_app
echo -e "33[05m33[35mStart install nginx and configure it...33[0m"
nginx_install_configure
echo -e "33[05m33[35mStart install mysql and configure it...33[0m"
mysql_install_configure
echo -e "33[05m33[35mStart install Libzip and configure it...33[0m"
libzip_install_configure
echo -e "33[05m33[35mStart install php and configure it...33[0m"
php_install_configure

/usr/local/nginx/sbin/nignx -s stop &> /dev/null && /usr/local/nginx/sbin/nginx 
echo """
""" >> /usr/local/nginx/html/test.php
curl http://127.0.0.1/test.php
if [ $? -eq "0"];then
    green "LNMP is ok !!!"
else
    red "Access PHP  Faild!!!"
fi

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/63381.html

相关文章

  • 详细整理5款较为常用的Linux VPS服务器WEB一键安装工具

    摘要:第一个人记忆中这款工具至今估计有十年左右时间当初也是个人站长为方便自己使用环境配置开发的。第二一键脚本也是由于个人站长提供的,经过几年的改善目前也是比较完善。 早年我们如果在Linux服务器配置网站环境的时候一般如何操作的?安装cPanel面板?这个是要花钱的,记忆中好像每个月需要十多美元,对于普通的个人站长用户来说确实是不小的费用。即便我们用破解版也不行,因为这个牵扯到安全问题。那我...

    techstay 评论0 收藏0
  • Centos7一键安装LNMP环境脚本

    摘要: #!/bin/bash read -p The installation process takes about 5 to 10 minutes, depending on the performance of your server. To confirm the installation of the lnmp environment, press the Enter key. ...

    Yumenokanata 评论0 收藏0
  • 一键安装LNMP或LAMP Web环境实现Linux服务器部署 PHP MySQL Nginx/Ap

    摘要:目前,我们看到的老蒋采用的部署的环境,在镜像中配置,于是我们会称作为。有没有一件傻瓜式安装工具脚本呢这里老蒋要推荐的来自国内比较老牌且一直更新维护的一键安装包,我们可以较为直观且无人值守的安装需要的网站服务器环境。如今我们建站较多的还是会选择VPS云服务器,很少会去选择虚拟主机,固然前者有很多的优点。不过相比虚拟主机不同的是,VPS云服务器需要我们自己配置WEB环境,而且我们较多的还是会选择...

    IntMain 评论0 收藏0
  • linux宝塔面板安装傻瓜教程:宝塔Linux面板7.6.0安装教程

    摘要:一键配置宝塔面板怎么安装到数据盘教程二个命令宝塔面板怎么安装到数据盘教程二个命令今天,刚买了一台香港云服务器,系统盘是,数据盘是,安装宝塔面板之后发现磁盘的容量不对Linux宝塔面板安装傻瓜教程:宝塔Linux面板7.6.0安装教程1.介绍宝塔Linux面板7.4.5版本是基于Centos开发的,为了最好的兼容性,请优先考虑使用Centos8.x系统系统兼容性顺序:Centos8.x > C...

    番茄西红柿 评论0 收藏2637
  • centos6.5和centos7如何搭建php环境

    摘要:总有人认为搭建环境很复杂,然后尝试安装一键安装包。考虑目前国内网站大部分采集文章十分频繁,更有甚者不注明原文出处,原作者更希望看客们查看原文,以防有任何问题不能更新所有文章,避免误导继续阅读 作者:白狼 出处:http://www.manks.top/linux_php.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法...

    Alex 评论0 收藏0

发表评论

0条评论

FullStackDeveloper

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<