在我的 Nginx 服务器环境上复制网站 (Wordpress) 的快速方法?

在我的 Nginx 服务器环境上复制网站 (Wordpress) 的快速方法?

出于测试目的,复制当前位于我的 VPS 上的 Nginx 服务器环境中的我自己的网站(Wordpress)之一的最快方法是什么?是否有脚本或实用程序可以自动执行此操作?

比如说,完整的网址是:

https://111.111.111.111/example.com || `example.com`.

该实用程序将复制该站点:

https://111.111.111.111/test

该网站是一个简单的Wordpress网站,有30个页面和5个基本插件。任何地方都没有自定义(系统或 Wordpress)。

答案1

这并不快,但下面的代码描述了我采取的方法。复制粘贴进行测试,如果有效,则将代码放入一个块中作为一个整体运行:

(
    The code...
)

代码

cd /var/www/html/
echo "1/3: Please enter the domain of the site you want to duplicate into a subdomain test version." && read domain
echo "2/3: Please enter the password for your Mysql root user." && read -s rps
echo "3/3: Please enter the password of the site's DB user." && read -s sps
ipa=$(ifconfig | grep -Po "inet addr:\K[^\s]+" | grep -v "^127")

rm -rf ./test/ ./test.sql
cp -r ./${domain} ./test/
sed -i "s/${domain}/test"/g ./test/wp-config.php
cp -r /etc/nginx/sites-available/${domain}.conf /etc/nginx/sites-available/test.conf
sed -i "s/${domain}/test"/g /etc/nginx/sites-available/test.conf
ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf

echo "DROP USER IF EXISTS 'test'@'localhost';" | mysql -u root -p"${rps}"
echo "DROP database IF EXISTS test;" | mysql -u root -p"${rps}"
echo "CREATE USER 'test'@'localhost' IDENTIFIED BY \"${sps}\";" | mysql -u root -p"${rps}"
echo "CREATE database test;" | mysql -u root -p"${rps}"
echo "GRANT ALL PRIVILEGES ON test.* TO test@localhost;" | mysql -u root -p"${rps}"
mysql -u root -p"${rps}" -e "SELECT user FROM mysql.user; SHOW grants FOR "test'@'localhost"; show databases;"

mysqldump -u root -p"${rps}" "${domain}" > test.sql
mysql -u test -p"${sps}" test < ./test.sql

cd test
wp search-replace "https://${domain}" "http://test.${ipa}/test" --allow-root
# Note that https:// && http:// are needed to apply a URL rewrite rule.

cat <<-TESTCONF > /etc/nginx/sites-available/test.${domain}.conf
    server {
        root /var/www/html/test/;
        server_name ${ipa} test.${domain};

        location / {
            index index.php index.html index.htm fastcgi_index;
            try_files $uri $uri =404 $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        listen 80;
    }
TESTCONF

unset domain rps sps ipa

相关内容