A fast way to duplicate a website (Wordpress) on my Nginx server environment?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












What is the fastest way to duplicate one of my own websites (Wordpress) which currently sits on my Nginx server environment on my VPS, for testing purposes? Is there a script or a utility that will make it automatically?



Say, the full url is:



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


and the utility will duplicate the site as to:



https://111.111.111.111/test



The website is a simple Wordpress website with 30 pages and 5 basic plugins. No customizations anywhere (system or Wordpress).







share|improve this question






















  • Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
    – peterh
    Nov 30 '17 at 1:59










  • Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
    – Arcticooling
    Nov 30 '17 at 8:45






  • 1




    You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
    – peterh
    Nov 30 '17 at 10:18







  • 1




    Btw, the script is good. Well-written. You are good in the command line. :-)
    – peterh
    Nov 30 '17 at 13:37










  • Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
    – Arcticooling
    Nov 30 '17 at 15:50














up vote
1
down vote

favorite












What is the fastest way to duplicate one of my own websites (Wordpress) which currently sits on my Nginx server environment on my VPS, for testing purposes? Is there a script or a utility that will make it automatically?



Say, the full url is:



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


and the utility will duplicate the site as to:



https://111.111.111.111/test



The website is a simple Wordpress website with 30 pages and 5 basic plugins. No customizations anywhere (system or Wordpress).







share|improve this question






















  • Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
    – peterh
    Nov 30 '17 at 1:59










  • Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
    – Arcticooling
    Nov 30 '17 at 8:45






  • 1




    You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
    – peterh
    Nov 30 '17 at 10:18







  • 1




    Btw, the script is good. Well-written. You are good in the command line. :-)
    – peterh
    Nov 30 '17 at 13:37










  • Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
    – Arcticooling
    Nov 30 '17 at 15:50












up vote
1
down vote

favorite









up vote
1
down vote

favorite











What is the fastest way to duplicate one of my own websites (Wordpress) which currently sits on my Nginx server environment on my VPS, for testing purposes? Is there a script or a utility that will make it automatically?



Say, the full url is:



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


and the utility will duplicate the site as to:



https://111.111.111.111/test



The website is a simple Wordpress website with 30 pages and 5 basic plugins. No customizations anywhere (system or Wordpress).







share|improve this question














What is the fastest way to duplicate one of my own websites (Wordpress) which currently sits on my Nginx server environment on my VPS, for testing purposes? Is there a script or a utility that will make it automatically?



Say, the full url is:



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


and the utility will duplicate the site as to:



https://111.111.111.111/test



The website is a simple Wordpress website with 30 pages and 5 basic plugins. No customizations anywhere (system or Wordpress).









share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 11:46

























asked Nov 29 '17 at 20:16









Arcticooling

83123




83123











  • Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
    – peterh
    Nov 30 '17 at 1:59










  • Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
    – Arcticooling
    Nov 30 '17 at 8:45






  • 1




    You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
    – peterh
    Nov 30 '17 at 10:18







  • 1




    Btw, the script is good. Well-written. You are good in the command line. :-)
    – peterh
    Nov 30 '17 at 13:37










  • Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
    – Arcticooling
    Nov 30 '17 at 15:50
















  • Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
    – peterh
    Nov 30 '17 at 1:59










  • Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
    – Arcticooling
    Nov 30 '17 at 8:45






  • 1




    You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
    – peterh
    Nov 30 '17 at 10:18







  • 1




    Btw, the script is good. Well-written. You are good in the command line. :-)
    – peterh
    Nov 30 '17 at 13:37










  • Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
    – Arcticooling
    Nov 30 '17 at 15:50















Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
– peterh
Nov 30 '17 at 1:59




Likely there is no fast way. It could be developed, but it would be a big work and it is a rare problem.
– peterh
Nov 30 '17 at 1:59












Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
– Arcticooling
Nov 30 '17 at 8:45




Dear @peterh please see my updated question with a code I tried to write for this task and its readme file.
– Arcticooling
Nov 30 '17 at 8:45




1




1




You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
– peterh
Nov 30 '17 at 10:18





You forgot to mention, that you have access to the file structure and to the database of the site. Your question looks like if you would want to duplicate a site to which you don't have any access. Exactly this ignorance is what drives many answerers total crazy here.
– peterh
Nov 30 '17 at 10:18





1




1




Btw, the script is good. Well-written. You are good in the command line. :-)
– peterh
Nov 30 '17 at 13:37




Btw, the script is good. Well-written. You are good in the command line. :-)
– peterh
Nov 30 '17 at 13:37












Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
– Arcticooling
Nov 30 '17 at 15:50




Hmm, sorry not to mention this clearly (I've now edited) and so much thanks!
– Arcticooling
Nov 30 '17 at 15:50










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










This is not fast, but the following code describes the approach I took. Copy paste to test, and if worked, run as one piece by putting the code in a block:



(
The code...
)


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





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407815%2fa-fast-way-to-duplicate-a-website-wordpress-on-my-nginx-server-environment%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    This is not fast, but the following code describes the approach I took. Copy paste to test, and if worked, run as one piece by putting the code in a block:



    (
    The code...
    )


    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





    share|improve this answer
























      up vote
      1
      down vote



      accepted










      This is not fast, but the following code describes the approach I took. Copy paste to test, and if worked, run as one piece by putting the code in a block:



      (
      The code...
      )


      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





      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        This is not fast, but the following code describes the approach I took. Copy paste to test, and if worked, run as one piece by putting the code in a block:



        (
        The code...
        )


        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





        share|improve this answer












        This is not fast, but the following code describes the approach I took. Copy paste to test, and if worked, run as one piece by putting the code in a block:



        (
        The code...
        )


        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 6 at 23:41









        Arcticooling

        83123




        83123



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407815%2fa-fast-way-to-duplicate-a-website-wordpress-on-my-nginx-server-environment%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)