私のNginxサーバー環境でWebサイト(Wordpress)を複製する簡単な方法は何ですか?

私のNginxサーバー環境でWebサイト(Wordpress)を複製する簡単な方法は何ですか?

テスト目的で、現在私のVPSのNginxサーバー環境にある私のWebサイト(Wordpress)の1つをコピーする最速の方法は何ですか?このタスクを自動的に実行できるスクリプトまたはユーティリティはありますか?

たとえば、完全なURLは次のようになります。

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

このユーティリティはサイトをコピーします。

https://111.111.111.111/test

このウェブサイトは、30ページと5つの基本プラグインを備えたシンプルなWordPressウェブサイトです。どこにも(システムまたは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

おすすめ記事