Categories
Wordpress

wordpress最快手动纯净部署

准备工作

一台vps带公网IP,ubuntu 18.04+ 即可(建议20.04),root用户

一个解析到你vps公网IP的域名【如 wp.v2ray.one】

第一部分 [ 手动配置wordpress ]

# 使用Ubuntu官方源安装必要的程序包和依赖包

# 使用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

# 预先配置需要用到的参数,如下:

# “域名wp库名,wp用户名,wp密码MySQL管理员密码

# “wp源码目录,ssl证书目录

# 定义域名,MySQL和wordpress(以下简称wp)需要用的参数
#0.设置你的解析好的域名,如本例子中的wp.v2ray.one
wp_domainName="wp.v2ray.one"

#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,并申请ssl证书

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,删除与nginx冲突的apache,启动php和nginx

#1.配置php
ln -s /run/php/php*.sock /run/php/php-fpm.sock
ln -s /etc/init.d/php*-fpm /etc/init.d/php-fpm 
#2.删除apache并清理其依赖包
/etc/init.d/apache2 stop
apt purge apache2 -y && apt autoremove -y
#3.启动php和nginx
/etc/init.d/php-fpm start
/etc/init.d/nginx restart
#4.添加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

浏览器输入你的域名,打开配置即可~

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服务启动

Leave a Reply

Your email address will not be published.