WordPress and WP CLI part 2

Most important part of web development is setting up the files/site in remote server. During the development demos are shown from Development Server. Once it is finalized, it need to be move into the client’s server.

In WordPress, problems starts from here. Content setup, Image url and many issues occurs immediately after it’s moved to client’s server. It would be great if database can be easily imported and URL can be replaced easily from existing Development Server.

Assuming the following points are already satisfied for this case :

  1. Client’s Server has SSH access.
  2. Client’s Server has WP CLI installed. [ Please read part 1 of this article to know how to install WP CLI using SSH ]. Part 1 is here : https://www.wordpress-studio.io/wordpress-and-wp-cli-part-1/
  3. Also the code has been maintained in Repository of GIT or Bitcucket or Any other SVN.
  4. Also the Client’s server is already connected.

What to setup git with WordPress installation :  

    1. Target folder is wp-content so the all the images and files will be stored in git.
    2. Git should be initialized at root folder along with .gitignore to remove the wp-admin, wp-include and other undesirable files.
  • wp db export db/development_server_db.txt [ it will create a file in the name by exporting the database specified ]
  1. Git push after commit.
  2. Repository will store all the file that are in Root folder.

How to setup the site at client remote server :

    1. Ssh login to client’s server.
    2. Clone repo in targeted folder git clone [email protected]:Project Name/Repo Name.git
    3. wp core download [ it will download the latest version ]
    4. wp core config –dbname=<databasename> –dbuser=<database username> –dbpass=<database password> –dbhost=<database hostname> [ it will generate the wp-config.php file with the specified settings.
    5. wp db create [ it will create db in the name you specified in last command ]
    6. wp core install –url=”studio.0effortthemes.com” –title=”Studio” –admin_user=”<admin username>” –admin_password=”<admin password>” –admin_email=”<admin email>” [ It will install WordPress at your specified URL, to check visit the URL ] **It will activate the default theme like Twenty Seventeen or else.
    7. It will create a setup of WordPress site, now db should be imported by wp db import  db/development_server_db.txt [ it import the db ], but it will contain the URL of development server, which we need to replace with client’s url.
  • wp search-replace  ‘development server ur’ ‘production server url’
  1. The above code will replace the development url to production url from database. But it will not be able to replace the url from Revolution Slider even some times from the Visual Composer page builder content.


The most of the development companies are following the above mentioned process these days to minimizing the errors while transferring the WordPress site from one to another server.

Example updated code can be forked from https://github.com/trisghosh/wordpress-automated-script