CentOS7 LNMP部署腳本

1、基於CentOS7.3_1908最小安裝模式,理論支持CentOS7各種安裝模式的系統
2、Nginx版本1.18.0;php版本7.4.7
3、源碼如下,更新或問題反饋

#!/bin/bash
if_update="n"
read -t 20 -p "please choose if Update System and Kernel,after 20s will choose not update 請選擇是否更新系統和內核,20秒後選擇不更新(y/n):    " if_update
if [ "$if_update" = "y" ]
then
     yum -y update
else 
    echo "Without Update 未選擇更新"
fi
useradd www
##########################################################################
echo 'install MariaDB 安裝MariaDB'
yum -y install mariadb mariadb-server
###########################################################################
echo 'Compile and install Nginx 1.18.0 stable 編譯安裝Nginx 1.18.0穩定版本 '
yum -y install wget
cd /root
mkdir LNMP
cd LNMP
if  [ ! -f "/root/LNMP/nginx-1.18.0.tar.gz" ];then
wget http://mirrors.sohu.com/nginx/nginx-1.18.0.tar.gz
fi
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
echo 'Dowmload and unzip successfully 下載並解壓成功'
#---------------------------------------------------------------------------
echo 'Install the compilation environment 安裝編譯環境'
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
yum -y install gcc
yum -y install zlib zlib-devel
./configure --prefix=/usr/local/nginx1.18 --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
make&&make install

#----------------------------------------------------------------------------
echo 'Install completed,register service and configure environment variables 安裝完成,開始註冊服務及配置環境變量'
cd /lib/systemd/system
rm -f nginx.service
wget http://47.107.149.229:8080/nginx.service
systemctl daemon-reload
systemctl start nginx.service
#----------------------------------------------------------------------------
if_enable_nginx=y
read -t 20 -p "if set nginx enable,after 20s it will be setted enable 是否設置nginx自啓動,20秒後默認設置自啓動(y/n): " if_enable_nginx
if [ "$if_enable_nginx" = "y" ]
then
systemctl enable nginx.service
fi
#----------------------------------------------------------------------------
echo 'export PATH=$PATH:/usr/local/nginx1.18/sbin' >> /etc/profile
source /etc/profile
echo 'Nginx completed nginx安裝已完成'
###############################################################################
echo 'Start install php-fpm 開始安裝php-fpm'
cd /root/LNMP
if  [ ! -f "/root/LNMP/php-7.4.7.tar.gz" ];then
wget http://mirrors.sohu.com/php/php-7.4.7.tar.gz
fi
tar -xvf php-7.4.7.tar.gz
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libcurl libcurl-devel libxslt-devel sqlite-devel
yum install epel-release -y
yum clean all&& yum makecache
yum install oniguruma oniguruma-devel -y
cd /root/LNMP/php-7.4.7
./configure --prefix=/usr/local/php7.4.7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-jpeg-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --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-xml  --enable-zip
make && make install
#-------------------------------------------------------------------------------
cd /usr/local/php7.4.7/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php7.4.7/etc/php-fpm.d
cp www.conf.default www.conf
cp /root/LNMP/php-7.4.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod o+x /etc/init.d/php-fpm
service php-fpm start
#-------------------------------------------------------------------------------
echo 'export PATH=$PATH:/usr/local/php7.4.7/bin' >> /etc/profile
source /etc/profile
###############################################################################
echo '環境配置完畢,您可以訪問主機地址,將看到nginx歡迎頁面'
echo '請確保已關閉防火牆或者放行80端口,請關閉selinux,雲主機請在安全組規則中放行80端口'
echo 'Nginx 支持使用Systemctl [start/stop/restart/status] nginx.service管理'
echo 'PHP支持使用Service php-fpm [start/stop/restart]管理'
read -p 'LNMP組件已經安裝完畢,是否允許修改Nginx配置文件和主頁以測試php解析是否正常(y/n): ' if_test_php
if [ "$if_test_php" = "y" ]
then
cp /usr/local/nginx1.18/conf/nginx.conf /usr/local/nginx1.18/conf/nginx.conf.back
rm -f /usr/local/nginx1.18/conf/nginx.conf
cd /usr/local/nginx1.18/conf
wget http://47.107.149.229:8080/nginx.conf
cd /usr/local/nginx1.18/html
echo '<?php phpinfo(); ?>' > index.php
/usr/local/nginx1.18/sbin/nginx -s reload
echo '請重新訪問頁面,您將看到php信息'
fi
exit 0
 


















 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章