AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 407815
Accepted
Arcticooling
Arcticooling
Asked: 2017-11-30 12:16:19 +0800 CST2017-11-30 12:16:19 +0800 CST 2017-11-30 12:16:19 +0800 CST

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

  • 772

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

说,完整的网址是:

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

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

https://111.111.111.111/test

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

scripting
  • 1 1 个回答
  • 650 Views

1 个回答

  • Voted
  1. Best Answer
    Arcticooling
    2018-01-07T15:41:36+08:002018-01-07T15:41:36+08:00

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

    (
        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
    
    • 2

相关问题

  • 启动应用程序的问题:命令行与 gui

  • 用于在日志文件中查找字符串的 Shell 脚本

  • 根据其中的值批量重命名(附加)CSV 文件

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    JSON数组使用jq来bash变量

    • 4 个回答
  • Marko Smith

    日期可以为 GMT 时区格式化当前时间吗?[复制]

    • 2 个回答
  • Marko Smith

    bash + 通过 bash 脚本从文件中读取变量和值

    • 4 个回答
  • Marko Smith

    如何复制目录并在同一命令中重命名它?

    • 4 个回答
  • Marko Smith

    ssh 连接。X11 连接因身份验证错误而被拒绝

    • 3 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Marko Smith

    systemctl 命令在 RHEL 6 中不起作用

    • 3 个回答
  • Marko Smith

    rsync 端口 22 和 873 使用

    • 2 个回答
  • Marko Smith

    以 100% 的利用率捕捉 /dev/loop -- 没有可用空间

    • 1 个回答
  • Marko Smith

    jq 打印子对象中所有的键和值

    • 2 个回答
  • Martin Hope
    EHerman JSON数组使用jq来bash变量 2017-12-31 14:50:58 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Drux 日期可以为 GMT 时区格式化当前时间吗?[复制] 2017-12-26 11:35:07 +0800 CST
  • Martin Hope
    AllisonC 如何复制目录并在同一命令中重命名它? 2017-12-22 05:28:06 +0800 CST
  • Martin Hope
    Steve “root”用户的文件权限如何工作? 2017-12-22 02:46:01 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST
  • Martin Hope
    Cbhihe 将默认编辑器更改为 vim for _ sudo systemctl edit [unit-file] _ 2017-12-03 10:11:38 +0800 CST
  • Martin Hope
    showkey 如何下载软件包而不是使用 apt-get 命令安装它? 2017-12-03 02:15:02 +0800 CST
  • Martin Hope
    youxiao 为什么目录 /home、/usr、/var 等都具有相同的 inode 编号 (2)? 2017-12-02 05:33:41 +0800 CST
  • Martin Hope
    user223600 gpg —list-keys 命令在将私钥导入全新安装后输出 uid [未知] 2017-11-26 18:26:02 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve