此脚本是LAMP环境安装WordPress脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.9文章源自小柒网-https://www.yangxingzhen.cn/6760.html
软件版本:文章源自小柒网-https://www.yangxingzhen.cn/6760.html
Nginx:1.16.1文章源自小柒网-https://www.yangxingzhen.cn/6760.html
Mysql:5.7.29文章源自小柒网-https://www.yangxingzhen.cn/6760.html
PHP:7.3.7文章源自小柒网-https://www.yangxingzhen.cn/6760.html
WordPress:5.4文章源自小柒网-https://www.yangxingzhen.cn/6760.html
[root@localhost ~]# vim auto_install_lnmp_wordpress.sh文章源自小柒网-https://www.yangxingzhen.cn/6760.html
#!/bin/bash
#Date:2020-4-13 14:08:55
#Author Blog:
# https://www.yangxingzhen.cn
#Author WeChat:
# 微信公众号:小柒博客
#Author mirrors site:
# https://mirrors.yangxingzhen.com
#About the Author
# BY:YangXingZhen
# Mail:xingzhen.yang@yangxingzhen.com
#Auto Install LNMP environment
source /etc/rc.d/init.d/functions
#Define Nginx path variables
NGINX_URL=http://nginx.org/download
NGINX_FILE=nginx-1.16.1.tar.gz
NGINX_FILE_DIR=nginx-1.16.1
NGINX_PREFIX=/usr/local/nginx
#Define Boost path variables
Boost_URL=https://mirrors.yangxingzhen.com/mysql
Boost_File=boost_1_59_0.tar.gz
#Define Mysql path variables
MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
MYSQL_FILES=mysql-5.7.29.tar.gz
MYSQL_FILES_DIR=mysql-5.7.29
MYSQL_PREFIX=/usr/local/mysql
MYSQL_DIR=/data/mysql
MYSQL_USER=mysql
#Define PHP path variables
PHP_URL=http://mirrors.sohu.com/php
PHP_FILE=php-7.3.7.tar.gz
PHP_FILE_DIR=php-7.3.7
PHP_PREFIX=/usr/local/php
USER=www
#Define ZIP path variables
ZIP_URL=https://nih.at/libzip
ZIP_FILE=libzip-1.2.0.tar.gz
ZIP_FILE_DIR=libzip-1.2.0
#Define Wordpress path variables
WORD_URL=https://mirrors.yangxingzhen.com/wordpress
WORD_FILES=wordpress-5.4-zh_CN.zip
WORD_FILES_DIR=wordpress
function Install_Nginx() {
#Install Nginx Soft
if [ ! -d ${NGINX_PREFIX} ];then
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ wget
cd ~ && wget -c ${NGINX_URL}/${NGINX_FILE}
tar zxf ${NGINX_FILE}
cd ${NGINX_FILE_DIR}
sed -i 's/1.16.1/ /;s/nginx\//nginx/' src/core/nginx.h
useradd -s /sbin/nologin www
./configure --prefix=${NGINX_PREFIX} \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module
if [ $? -eq 0 ];then
make && make install
action "NGINX Install Success..." /bin/true
else
action "NGINX Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[32m Nginx has been installed \033[0m"
fi
}
function Install_Mysql() {
if [ ! -d ${MYSQL_PREFIX} ];then
#Install Package
yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl
#Install Boost
cd ~ && wget -c ${Boost_URL}/${Boost_File}
tar zxf ${Boost_File} -C /usr/local/
#Install MYSQL
cd ~ && wget -c ${MYSQL_URL}/${MYSQL_FILES}
tar zxf ${MYSQL_FILES}
cd ${MYSQL_FILES_DIR}
cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=${MYSQL_DIR} \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_READLINE=1 \
-DMYSQL_USER=${MYSQL_USER} \
-DWITH_SSL=yes
if [ $? -eq 0 ];then
make && make install
action "The MYSQL Install Sussess..." /bin/true
else
action "The MYSQL Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe MYSQL already Install...\033[0m"
exit 1
fi
}
function Install_PHP() {
#Install Libzip
yum –y install wget gcc gcc-c++
cd ~ && wget -c ${ZIP_URL}/${ZIP_FILE}
tar zxf ${ZIP_FILE}
cd ${ZIP_FILE_DIR}
./configure
if [ $? -eq 0 ];then
make && make install
action "The Libzip Install Sussess..." /bin/true
else
action "The Libzip Install Failed..." /bin/false
exit 1
fi
cat >/etc/ld.so.conf <<EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
ldconfig -v
#Install PHP
if [ ! -d ${PHP_PREFIX} ];then
#Install Package
yum -y install epel-release
yum -y install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devellibxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel cmake
cd ~ && wget -c ${PHP_URL}/${PHP_FILE}
tar zxf ${PHP_FILE}
cd ${PHP_FILE_DIR}
./configure --prefix=${PHP_PREFIX} \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=${USER} \
--with-fpm-group=${USER} \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
if [ $? -eq 0 ];then
\cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
make && make install
action "The PHP Install Sussess..." /bin/true
else
action "The PHP Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe PHP already Install...\033[0m"
exit 1
fi
}
function LNMP_Config() {
#Nginx config
useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/sbin
cat >${NGINX_PREFIX}/conf/nginx.conf <<EOF
user ${USER} ${USER};
worker_processes auto;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 10240;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log logs/access.log main;
error_log logs/error.log warn;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 64k;
gzip_http_version 1.1;
gzip_comp_level 4;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
large_client_header_buffers 4 4k;
client_header_buffer_size 4k;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
server {
listen 80;
server_name localhost;
location / {
root html/wordpress;
index index.php index.html index.htm;
}
location ~* \.php$ {
root html/wordpress;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF
#Config PHP
\cp php.ini-production /etc/php.ini
\cp ${PHP_PREFIX}/etc/php-fpm.conf.default ${PHP_PREFIX}/etc/php-fpm.conf
\cp ${PHP_PREFIX}/etc/php-fpm.d/www.conf.default ${PHP_PREFIX}/etc/php-fpm.d/www.conf
\cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
[www]
listen = 0.0.0.0:9000
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/\$pool.log.slow
EOF
#Mysql Config
useradd -s /sbin/nlogin mysql >/dev/null 2>&1
mkdir -p ${MYSQL_DIR}
chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
cat >/etc/my.cnf <<EOF
[mysqld]
#数据存储目录
datadir = ${MYSQL_DIR}
#socket通信文件
socket = /tmp/mysql.sock
#使用mysql用户启动
user = ${MYSQL_USER}
#MYSQL服务运行的端口号
port = 3306
#开启bin-log日志
log-bin = mysql-bin
#MYSQL服务ID号
server-id = 1
#定义error错误文件
log-error = ${MYSQL_DIR}/mysqld.log
#PID文件路径
pid-file = mysqld.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#设置字符集为utf8
character-set-server = utf8
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysql]
default-character-set = utf8
EOF
#Initialization Mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
\cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
chmod o+x /etc/init.d/mysqld
#Config iptables(firewalld)、selinux
SYS_VERSION=$(awk -F. '{print $1}' /etc/redhat-release |awk '{print $NF}')
if [ ${SYSTEM_VERSION} -eq 6 ];then
service iptables stop
chkconfig iptables off
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
else
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
fi
#Start MYSQL、php-fpm、nginx and Add MySQL、php-fpm、nginx boot self start
${NGINX_PREFIX}/sbin/nginx
systemctl start php-fpm
/etc/init.d/mysqld start
grep -qw "${NGINX_PREFIX}" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
echo "${NGINX_PREFIX}/sbin/nginx" >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
systemctl enable php-fpm
chkconfig --add mysqld
chkconfig mysqld on
chmod +x /etc/rc.d/rc.local
}
function Install_WordPress (){
#Wordpress Config
cd ~ && wget ${WORD_URL}/${WORD_FILES}
[ -f /usr/bin/unzip ] || yum -y install unzip
unzip ${WORD_FILES} -d ${NGINX_PREFIX}/html
chown -R www.www ${NGINX_PREFIX}/html/wordpress
mysql -e "create database wordpress charset=utf8;"
mysql -e "grant all on wordpress.* to wordpress@'localhost' identified by '123456';"
mysql -e "flush privileges"
}
function Main (){
Install_Nginx
Install_Mysql
Install_PHP
LNMP_Config
Install_WordPress
}
Main
脚本执行方式:文章源自小柒网-https://www.yangxingzhen.cn/6760.html
[root@localhost ~]# sh auto_install_lnmp_wordpress.sh文章源自小柒网-https://www.yangxingzhen.cn/6760.html 文章源自小柒网-https://www.yangxingzhen.cn/6760.html
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
![weinxin](https://www.yangxingzhen.com/images/weixin.jpg)
我的微信
微信公众号
微信扫一扫,关注我!
![weinxin](https://www.yangxingzhen.com/images/weixingongzhonghao.png)
我的公众号
评论