第二部分 [ 一键批处理部署wordpress ]
curl -s https://raw.githubusercontent.com/HappyLife-page/wordpress/main/wordpress_installation.sh | bash -s wp.v2ray.one
# wp.v2ray.one 改为你的解析好的域名即可
你可以打开链接https://raw.githubusercontent.com/HappyLife-page/wordpress/main/wordpress_installation.sh直接查看批处理的完整内容,这里粘贴原始批处理如下:
#!/bin/bash
# Auth: happylife
# Desc: wordpress installation script
# Plat: ubuntu 18.04 20.04
# Eg : bash wordpress_installation.sh "你的域名"
# 使用Ubuntu官方源安装nginx php mysql和一些依赖
apt install php php-fpm php-opcache php-mysql nginx php-gd php-xmlrpc php-imagick php-mbstring php-zip php-json php-mbstring php-curl php-xml mariadb-server pwgen expect -y
# 定义域名,MySQL和wordpress(以下简称wp)需要用的参数
#0.设置你的解析好的域名
wp_domainName="$1"
#1.随机生成MySQL的root用户密码
mysql_root_pwd="`pwgen 8 1`"
#2.随机生成wp用户名
wp_user_name="`pwgen -0 8 1`"
#3.随机生成wp密码
wp_user_pwd="$(pwgen -cny -r "\"\\;'\`" 26 1)"
#4.随机生成wp数据库名
wp_db_name="`pwgen -A0 9 1`"
#5.随机生成并创建wp源码目录
wp_code_dir="$(mkdir -pv "/`pwgen -A0 8 3 | xargs |sed 's/ /\//g'`" |awk -F"'" END'{print $2}')"
#6.以时间为基准随机创建一个存放ssl证书的目录
ssl_dir="$(mkdir -pv "${wp_code_dir}/ssl/`date +"%F-%H-%M-%S"`" |awk -F"'" END'{print $2}')"
# 执行mysql_secure_installation命令优化MySQL配置
# 包括设置root密码,移除匿名用户,禁用root账户远程登陆,删除测试库,和重载权限表使优化生效
/usr/bin/expect <<-EOCCCCCC
spawn /usr/bin/mysql_secure_installation
expect "Enter current password for root (enter for none):"
send "\r"
expect "Set root password? "
send "Y\r"
expect "New password: "
send "${mysql_root_pwd}\r"
expect "Re-enter new password: "
send "${mysql_root_pwd}\r"
expect "Remove anonymous users?"
send "Y\r"
expect "Disallow root login remotely?"
send "Y\r"
expect "Remove test database and access to it?"
send "Y\r"
expect "Reload privilege tables now?"
send "Y\r"
expect eocccccc;
EOCCCCCC
# 下载wp,创建wp库,设置wp用户名和密码并设置访问权限
#1.下载wp最新源码,并解压到wp目录
curl https://wordpress.org/latest.tar.gz | tar xz -C ${wp_code_dir}
#2.授权nginx用户访问wp源码目录
chown -R www-data.www-data ${wp_code_dir}
#3.创建wp库,给wp设置MySQL用户名和密码并授予访问权限
mysql -uroot -p${mysql_root_pwd} <<-EOC
#3.1 创建wp数据库
create database ${wp_db_name};
#3.2 创建wp用户并设置密码
create user ${wp_user_name}@'localhost' identified by "${wp_user_pwd}";
#3.3 授权wp用户访问wp库
grant all privileges on ${wp_db_name}.* to ${wp_user_name}@'localhost';
#3.4 刷新权限使其生效
flush privileges;
EOC
# 安装acme,并申请加密证书
source ~/.bashrc
if nc -z localhost 443;then /etc/init.d/nginx stop;fi
if ! [ -d /root/.acme.sh ];then curl https://get.acme.sh | sh;fi
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d "$wp_domainName" -k ec-256 --alpn
~/.acme.sh/acme.sh --installcert -d "$wp_domainName" --fullchainpath $ssl_dir/${wp_domainName}.crt --keypath $ssl_dir/${wp_domainName}.key --ecc
chown www-data.www-data $ssl_dir/*
## 把续签证书命令添加到计划任务
echo -n '#!/bin/bash
/etc/init.d/nginx stop
"/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" &> /root/renew_ssl.log
/etc/init.d/nginx start
' > /usr/local/bin/ssl_renew.sh
chmod +x /usr/local/bin/ssl_renew.sh
(crontab -l;echo "15 03 */3 * * /usr/local/bin/ssl_renew.sh") | crontab
# 给wp添加nginx配置文件
echo "
server {
listen 80;
server_name $wp_domainName;
return 301 https://"'$host$request_uri'";
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name $wp_domainName;
ssl_certificate $ssl_dir/${wp_domainName}.crt;
ssl_certificate_key $ssl_dir/${wp_domainName}.key;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
root ${wp_code_dir}/wordpress;
index index.php;
"'location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location = /xmlrpc.php {
deny all;
access_log off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}'"
}
" >> /etc/nginx/conf.d/wordpress.conf
# 配置php
ln -s /run/php/php*.sock /run/php/php-fpm.sock
ln -s /etc/init.d/php*-fpm /etc/init.d/php-fpm
# 删除apache并清理其依赖包
/etc/init.d/apache2 stop
apt purge apache2 -y && apt autoremove -y
# 重启php和nginx
/etc/init.d/php-fpm start
/etc/init.d/nginx restart
# 添加php开机启动服务
systemctl enable php7.4-fpm
# 输出配置信息
#wp安装配置信息文件
wp_ins_info="/root/wp_installation_info.txt"
> $wp_ins_info
echo "你的域名: $wp_domainName" | tee $wp_ins_info
echo "MySQL root密码: $mysql_root_pwd" | tee -a $wp_ins_info
echo "wp库名: $wp_db_name" | tee -a $wp_ins_info
echo "wp用户名: $wp_user_name" | tee -a $wp_ins_info
echo "wp密码: $wp_user_pwd" | tee -a $wp_ins_info
echo "wp源码目录: $wp_code_dir" | tee -a $wp_ins_info
echo "ssl证书目录: $ssl_dir" | tee -a $wp_ins_info
对比该批处理和第一部分的手动纯净安装内容你会发现,哟,内容基本都是一样的吗???
没错,以“#”开头的都是注释,你完全可以把第一部分的内容当作脚本的内容复制粘贴到你的命令行终端 执行即可
唯一的区别就是:一键批处理后面跟上你的域名,而手动安装需要手动设置你的域名。没错,就是这样简单,还在等什么?赶快开一台测试机试试手吧,你也可以成为安乐侯!
我所做的就是整合了那些可以命令执行的操作到批处理里,方便快速部署配置,而不用再手动操作每一个步骤那么麻烦!!!
现在开始,丢掉你每次一行一行执行命令的烦恼,快来试试吧~
声明:
本批处理开源,任何人都可以拿去修改,再发!
另外对批处理感兴趣的朋友,这是一个入门学习的好材料哦
项目地址:https://github.com/HappyLife-page/wordpress
4 replies on “wordpress最快手动纯净部署”
站主你好,看了你的文章,配置好v2ray,然后又看到这篇文章。
请问如何在同一个VPS上同时配置v2ray和word press?
能出一个简单的教程吗?谢谢!
直接按照该帖子在v2ray服务器上跑一遍即可,域名解析使用 http://www.xxx最好,当然和v2ray域名相同都行(需修改配置稍微麻烦些而已)
已经有v2ray+wordpress二合一脚本:
https://github.com/HappyLife-page/v2ray/blob/main/v2ray_wordpress_installation.sh
部署方案与该帖子雷同,只需要解析好域名即可(该域名是v2ray和wordpress共用,因为wp属于常规站点,最好使用如v2ray.one或www.v2ray.one,而不是一个不规则的二级域名如xmt.v2ray.one)
如本站的域名www.happylife.page
站主你好,看了你的文章,用v2ray+wordpress二合一脚本安装配置后,并套了cf CDN,v2ray 和 WP 都访问正常,WP能编辑文章。在重启了VPS后,v2ray工作正常,但访问域名的网页报cf Bad gateway Error code 502, host error。vps地址可以ssh登录,我尝试在浏览器输入vps的原始ip地址,网页显示“Welcome to nginx!” 我怀疑是nginx 配置问题,尝试运行’nginx -t’ 后,显示conf文件正常。 帮忙分析是哪里出错了,导致无法访问wordpress?
应该是你的vps重启后php服务没启动,使用 /etc/init.d/php7.4-fpm start 启动看看
使用 systemctl enable php7.4-fpm 添加php开机服务启动
一键部署里貌似没有添加,后面抽空会添加开机php服务启动