debian8系统下lnmp最新版本 一键安装脚本,简单方便!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了debian8系统下lnmp最新版本 一键安装脚本,简单方便!相关的知识,希望对你有一定的参考价值。

#!/bin/bash

#

#

aptd="/etc/apt"

srcd="/usr/src"

openssl="openssl-1.0.2k.tar.gz"

nginx_key="nginx_signing.key"

php7="php-7.1.2.tar.gz"

pwds=`pwd`

#判断当前是否为root用户

#

CheckUid()

{

check_user=`whoami`;

if [ "$check_user" = "root" ];then

  echo "You user is root";

else

 echo "You Must USE root login" && exit 1;

fi

}

Main()

{

CheckUid;

}

Main

#

#

#备份debian系统自带源#

cd $aptd

cp sources.list sources.list.old.bak

#下载国内163镜像源,替换自带源#

wget http://mirrors.163.com/.help/sources.list.jessie

rm -rf sources.list

mv sources.list.jessie sources.list

#更新源

aptitude update

#设置时区

 rm -rf /etc/localtime

 ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#

 aptitude install ntp ntpdate -y

 ntpdate -u pool.ntp.org

 

#安装make包及php需要的依赖包!若未安装make包,openssl\php无法编译成功

#先查询是否安装了,若未安装则执行安装!

for packages in build-essential autoconf automake libtool bison re2c build-essential autoconf automake libtool bison re2c libxml2-dev libssl-dev libbz2-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev libmcrypt-dev libmysqlclient15-dev libpspell-dev librecode-dev libcurl4-gnutls-dev libgmp-dev libgmp3-dev librecode-dev libpspell-dev libmcrypt-dev libreadline-dev libtidy-dev libxslt-dev;

do

dpkg -l | grep $packages;

if [ $? = 0 ];then

  echo "packages is installing";

else

aptitude install $packages -y;

fi

done

#

#

sleep 5

#安装Nginx|Mysql

cd $srcd

#判断是否有key文件,并且添加!

if [ ! -e "$nginx_key" ];then

   wget http://nginx.org/packages/keys/nginx_signing.key && apt-key add nginx_signing.key;

else

   apt-key add nginx_signing.key;

fi

#添加nginx-stable最新版本源!

echo "#nginx" >> /etc/apt/sources.list

echo "deb http://nginx.org/packages/debian/ jessie nginx " >> /etc/apt/sources.list

echo "deb-src http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list

#更新源

aptitude update && aptitude update

#开始安装

aptitude install nginx -y

#mysql(这里安装mysql5.5) 安装需要手动输入密码,请勿离开!

aptitude install mysql-server -y


#进入软件存放目录

cd $srcd

#安装openssl

if [ ! -e "$openssl" ];then

   wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz && tar zxf $openssl;

fi

cd openssl-1.0.2k

./config

#判断config是否成功

if [ $? = "0" ];then

  make && make install;

else

  exit 1;

fi

#

#

#进入程序存放目录

cd $srcd

#判断是否有php程序,没有下载!

if [ ! -e "$php7" ];then

   wget http://cn2.php.net/distributions/php-7.1.2.tar.gz && tar zxf $php7;

fi

#开始编译

cd php-7.1.2

./configure --prefix=/usr/local/php7 --sysconfdir=/etc/php7 \

--with-config-file-path=/etc/php7 --enable-fpm --with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib \

--with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir \

--with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir \

--with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session  \

--enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv \

--enable-inline-optimization --enable-shared --enable-bcmath \

--enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex \

--enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline \

--with-recode --with-tidy

#

if [ $? = "0" ];then

  make && make install;

else

  exit 1;

fi

#

#

#

dpkg -l | grep nginx

dpkg -l | grep mysql

/usr/local/php7/sbin/php-fpm -v


#备份nginx配置文件

cp /etc/nginx/nginx.conf  /etc/nginx/nginx.conf.bak

#修改配置文件nginx 用户

sed -i "1s/nginx/www-data/" /etc/nginx/nginx.conf

#备份nginx网站主机配置文件

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

#删除了默认的配置文件,自己写

rm -rf /etc/nginx/conf.d/default.conf

cat >/etc/nginx/conf.d/lnmp.conf << EOF

server {

listen       80;

server_name  localhost;

location / {

root   /usr/share/nginx/html;

index index.php index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;

}

location ~ \.php$ {

root           /usr/share/nginx/html;

fastcgi_pass   unix:/run/php/php7.0-fpm.sock;

fastcgi_index  index.php;                    

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include           fastcgi_params;

}

}

EOF


#暂停5秒

sleep 5

#复制php.ini到目录

cd $srcd/php-7.1.2/php.ini-production /etc/php7/php.ini

#php这个配置默认为default后缀,需要改成.conf

cd /etc/php7

cp -r php-fpm.conf.default php-fpm.conf

#备份原来配置,并且修改名称,也可以不要删除原来原来配置

cd /etc/php7/php-fpm.d

cp www.conf.default www.conf.default.bak

mv www.conf.default lnmp.conf

#修改php配置文件

sed -i "s%listen = 127.0.0.1:9000%listen = /run/php/php7.0-fpm.sock%" lnmp.conf

sed -i "s/user = nobody/user = www-data/" lnmp.conf

sed -i "s/group = nobody/group = www-data/" lnmp.conf

#测试lnmp是否安装成功

cd

cat >/usr/share/nginx/html/index.php<<EOF

<?php

phpinfo();

?>

EOF

#

sleep 5 && cd

echo "+------------------------------------------------------------------------+"

echo "|            Congratulations on your success!                                       |"

echo "+------------------------------------------------------------------------+"

echo "|   A tool to auto-compile & install LNMP/LNMPA/LAMP on Debian8  |"

echo "+------------------------------------------------------------------------+"

echo "|   For more information please visit http:http://sadoc.blog.51cto.com  |"

echo "+------------------------------------------------------------------------+"

#启动服务

#systemctl start mysql.service

#systemctl start nginx.service

#/usr/local/php7/sbin/php-fpm

#若启动报错php,查看是否有如下目录,也可以查看log日志/var/log/nginx/error.log!

#mkdir /run/php/

#结束进程

#killall php-pfm

#启动

#/usr/local/php7/sbin/php-fpm

#cd /run/php/

#chmod 777 php7.0-fpm.sock

#cd

#查看进程

#ps -ef | grep php-fpm

#ps -ef | grep nginx

#ps -ef | grep mysql


exit 1



#****复制以上到x.sh*****#

以上是关于debian8系统下lnmp最新版本 一键安装脚本,简单方便!的主要内容,如果未能解决你的问题,请参考以下文章

shell-安装lnmp,一键脚本_简单版

LNMP 一键安装包 版本服务任你选

LNMP一键环境安装多PHP版本共存的方法

一键安装lnmp脚本(包括软件版本)

ss-panel(ss-R)前后端一键安装脚本(转)

一键安装lnmp脚本