Centos7 LNMP一键安装脚本 - AFF大佬 - 分享有价值的主机信息和服务器运维编程技术
当前位置: 主页 » 技术干货 » Centos7 LNMP一键安装脚本

Centos7 LNMP一键安装脚本

   affdalao      2017年12月08日   阅读 167 次     0 评论   Tags: ·

update: 2017-12-19 PHP7.2.0开始移除mcrypt模块,移除libmcrypt、libmcrypt-devel、mcrypt包和相应的PHP编译–enable-gd-native-ttf 和–with-mcrypt参数。
安装mcrypt参考:编译安装的PHP7.2如何安装mcrypt扩展

每次配置环境的时候太麻烦了,要各种操作,今天写了这个一键安装脚本,此脚本只安装,nginx最新稳定版、mariadb-10.2.x最新稳定版、PHP可指定版本默认php-7.2.0,可以自定义网址,不需要带www,比如:affdalao.com,默认支持mysql远程连接,为了安全并没有在防火墙添加远程连接3306端口,默认开启22和80端口。

使用方法:

wget --no-check-certificate -O lnmp.sh https://raw.githubusercontent.com/mrlile/shell/master/lnmp.sh
chmod +x lnmp.sh
bash lnmp.sh

脚本内容:

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#A tool to auto-compile & install Nginx+MySQL+PHP on Centos7 for laster stable version
#BY:Mr lile  Web:https://www.affdalao.com  Date:2017/12/9    version:1.0

#soft download dir 
DIR=/usr/local/src

read  -t 30  -p  "Are you sure want to install LNMP,please input y/n :  "  lnmp   

if [ "$lnmp" == "y" ]
then 
echo -e "lnmp will be install" >> /usr/local/src/lnmp.log
else
exit
fi

read  -t 30  -p  "please input you website url default localhost :  "  websiteurl   

if [ -z "$websiteurl" ]
then 
                        websiteurl="localhost"
echo  "website url default localhost"
fi

read -t 30 -p  "please enter the mysql passwd.(Default password: root) :  "   mysqlrootpwd

if [  -z "$mysqlrootpwd"  ]
then 
                        mysqlrootpwd="root"
echo  "MySQL root password:root"
fi

read -t 30 -p  "please enter the PHP version.(Default version: 7.2.0) :  "   phpversion

if [  -z "$phpversion"  ]
then 
                         phpversion="7.2.0"
echo  "PHP version:7.2.0"
fi

yum -y autoremove nginx*
yum -y autoremove httpd*
yum -y autoremove php*
yum -y autoremove mysql*
yum -y autoremove mariadb*

#delete mysql and nginx dir
rm -rf /var/lib/mysql/
rm -rf /etc/my.cnf
rm -rf /etc/nginx/

yum -y install epel-release.noarch

yum -y install firewalld

yum -y install wget gcc gcc-c++ make cmake  perl autoconf automake libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel pcre pcre-devel libtool  pcre-devel libaio-devel libaio bzip2-devel libcurl-devel gd-devel bison bison-devel  libmcrypt libmcrypt-devel

yum update  -y


cd $DIR
wget http://us2.php.net/distributions/php-$phpversion.tar.gz 

tar xf php-$phpversion.tar.gz

echo ""
echo "===================nginx will be install ============================"
echo ""

sleep 5;

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum -y install nginx

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

cat > /etc/nginx/conf.d/default.conf
EOF

echo "================LNMP install  is ok,now start LNMP and enable LNMP ======================="
echo ""
systemctl enable nginx.service
systemctl enable mariadb.service
systemctl enable php-fpm.service

/usr/bin/systemctl restart php-fpm
/usr/bin/systemctl restart nginx
/usr/bin/systemctl restart mysql

echo "================set firewalld default 80  22======================="

systemctl restart firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --reload


echo ""
echo "============LNMP install  is ok, The path of some dirs:=============="

echo ""
echo "The path of some dirs:"
echo "mysql conf file :   /etc/my.cnf"
echo "php install dir :     /usr/local/php"
echo "php conf file :     /usr/local/php/etc/php.ini"
echo "nginx conf file :   /etc/nginx/nginx.conf and /etc/nginx/conf.d/"
echo "web dir :     /usr/local/nginx/html"
echo "The mysql root passwd is : $mysqlrootpwd" 
echo "please input http://ip/info.php, to checkout the lnmp is working!!!"
echo "Enjoy it !"

exit

  • 版权声明:本文版权归AFF大佬和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 AFF大佬 整理发布,欢迎转载,转载请带版权。

  • 来源:AFF大佬 ( https://www.affdalao.com/ ),分享有价值的主机信息和服务器运维编程技术。
  • 链接:https://www.affdalao.com/164.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注