Script example for reinstalling WordPress with one click in Linux

Source: Internet
Author: User
Tags wordpress database
This article mainly introduces the script example for re-installing WordPress with one click in Linux, which is especially suitable for operations on VPS servers. if you need it, you can refer to the website which may be migrated from time to time, if the database is lost due to misoperations, I wrote a script to reinstall wordpress with one click to save time.

I just wrote a rough description. You can modify the script as needed.

Usage conditions:

This script is mainly used when the website is migrated and completely re-installed. That is to say, I only import the database. I have not used the following scripts for wordpress themes, plug-ins, and other files. if necessary, you can modify them by yourself (as mentioned below ).

Prepare the following files:

  • Original wordpress profile wp-config.php
  • Original wordpress database backup file
  • Wget is installed in the system (most of them are installed by default)

#! Bin/sh # vps wordpress one-click re-installation script # global settingUSERNAME = "root" # Database username PASSWORD = "ksharpdabu.info" # database password dbname = "wordpress" # Name of the database to be imported BACKUPSQL = "/home/ksharpdabu. SQL "# backup SQL file absolute path OLD_WP-CONFIG ="/home/wp-config.php "# The absolute path previously saved to the wp-config.php file # setting end !! WEBROOT = "/home/wwwroot" # Website root directory http://www.dabu.info/ ? P = 4329 echo "################################### ################################# \ n "echo" please backup your website data when you run this shell script !!!! \ N "echo" please backup your website data when you run this shell script !!!! \ N "echo" please backup your website data when you run this shell script !!!! \ N "echo "################################### #################################\ n "get_char () # The function of this code section is to allow the user to enter any key to continue executing the script, is a common code segment {SAVEDSTTY = 'stty-G' stty-echo stty cbreak dd if =/dev/tty bs = 1 count = 1 2>/dev/null stty-raw stty echo stty $ SAVEDSTTY} echo "" echo "Press any key to start... "char = 'get _ char 'create _ db =" create database if not exists $ {DBNAME} "mysql-u $ {USERNAME}-p $ {PASSWORD}-e" $ {create_db} "# create a database named wordpress, if not http://www.dabu.info/ ? P = 4329 wget-c http: # cn.wordpress.org/wordpress-3.7.1-zh_CN.zip # Download the wordpress website program unzip wordpress-3.7.1-zh_CN.zip # unzip the wordpress program cd wordpress # switch to the decompressed wordpress directory cp. /* $ {WEBROOT} # Copy the website program to the website root directory \ cp $ {OLD_WP-CONFIG} $ {WEBROOT} # put the original wordpress configuration file wp-config.php to the site root directory mysql-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME} <$ {BACKUPSQL} # import the database you backed up to the wordpress database for echo "######### ######################################## ################# \ n "echo" please view you blog to check the success or failure. \ n "echo" view my blog: http://www.dabu.info/ If you have question !! \ N "echo "################################### #################################\ n "#! Bin/sh # vps wordpress one-click re-installation script # global settingUSERNAME = "root" # Database username PASSWORD = "ksharpdabu.info" # database password dbname = "wordpress" # Name of the database to be imported BACKUPSQL = "/home/ksharpdabu. SQL "# backup SQL file absolute path OLD_WP-CONFIG ="/home/wp-config.php "# The absolute path previously saved to the wp-config.php file # setting end !! WEBROOT = "/home/wwwroot" # Website root directory http://www.dabu.info/ ? P = 4329 echo "################################### ################################# \ n "echo" please backup your website data when you run this shell script !!!! \ N "echo" please backup your website data when you run this shell script !!!! \ N "echo" please backup your website data when you run this shell script !!!! \ N "echo "################################### #################################\ n "get_char () # The function of this code section is to allow the user to enter any key to continue executing the script, is a common code segment {SAVEDSTTY = 'stty-G' stty-echo stty cbreak dd if =/dev/tty bs = 1 count = 1 2>/dev/null stty-raw stty echo stty $ SAVEDSTTY} echo "" echo "Press any key to start... "char = 'get _ char 'create_db =" create database if not exists $ {DBNAME} "mysql-u $ {USERNAME}-p $ {PASSWORD}-e" $ {create_db} "# create a database named wordpress, if not http://www.dabu.info/ ? P = 4329 wget-c http: # cn.wordpress.org/wordpress-3.7.1-zh_CN.zip # Download the wordpress website program unzip wordpress-3.7.1-zh_CN.zip # unzip the wordpress program cd wordpress # switch to the decompressed wordpress directory cp. /* $ {WEBROOT} # Copy the website program to the website root directory \ cp $ {OLD_WP-CONFIG} $ {WEBROOT} # put the original wordpress configuration file wp-config.php to the site root directory mysql-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME} <$ {BACKUPSQL} # import the database you backed up to the wordpress database for echo "######### ######################################## ################# \ n "echo" please view you blog to check the success or failure. \ n "echo" view my blog: http://www.dabu.info/ If you have question !! \ N "echo "################################### #################################\ n"

Ps: modify the script as needed

1. if you have not only backed up the database, but also backed up the website plug-ins and other files, you can directly:

Wget-c http: # cn.wordpress.org/wordpress-3.7.1-zh_CN.zip # Download the wordpress website program unzip wordpress-3.7.1-zh_CN.zip # unzip the wordpress program cd wordpress # switch to the decompressed wordpress directory cp. /*/home/wwwroot/# Copy the website program to the website root directory \ cp $ {OLD_WP-CONFIG} $ {WEBROOT} wget-c http: # cn.wordpress.org/wordpress-3.7.1-zh_CN.zip # Download the wordpress website program unzip wordpress-3.7.1-zh_CN.zip # unzip the wordpress program cd wordpress # switch to the decompressed wordpress directory cp. /*/home/wwwroot/# Copy the website program to the website root directory \ cp $ {OLD_WP-CONFIG} $ {WEBROOT}

Delete, replace it with the decompress copy command for all the backup files on the website.

Assume that I have backed up the entire/wwwrootdirectory as all.tar.gz.

Then it is written:

tar -zvxf all.tar.gz  /home

2. if you only need to reinstall

Then you need to add a command to delete the original wordpress database or table:

drop database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.