Easy way to migrate wordpress Database and wp-content from Dev to Prod Environment

      Comments Off on Easy way to migrate wordpress Database and wp-content from Dev to Prod Environment

It is very important to know about wordpress import and export when we handle wordpress servers. Database will have all the changes in wordpress so it is very important to keep backup to restore when data corruption happens.

Content Export and import:

Step 1 :

Login to development server for example beta.devopstree.com server, and copy uploads and themes directory from wp-content directory

# cd /var/www/html/wp-content/
# tar czf wp-content-uploads.tar.gz uploads
# tar czf wp-content-themes.tar.gz themes


# scp -r -i keyfile.pem [email protected]:/var/www/html html > tmp

We have prod server key in dev server’s /home/ec2-user location or some other locations. So you should copy tar file into prod server using scp

Step 2 : Copy tar file to production server.

Copy the compressed tar file to the production environment,

# scp -i /home/ec2-user/devopstree_key.pem  wp-content-uploads.tar.gz  wp-content-themes.tar.gz [email protected]:~/

==> Both files will be copied to production server.

Step 3 : Restore uploads and themes in prod server

==> Restore uploads and themes directory which is copied from dev server to prod server

# mv /home/ec2-user/wp-content-uploads.tar.gz /var/www/html/wp-content/

# mv /home/ec2-user/wp-content-themes.tar.gz /var/www/html/wp-content/

==> Move old upload contents to tmp directory and untar new contents,

# mv /var/www/html/wp-content/uploads /tmp

# tar -zxvf  /var/www/html/wp-content/wp-content-uploads.tar.gz

==> Move old themes directory to tmp directory and untar new.

# mv /var/www/html/wp-content/themes /tmp

# tar -zxvf  /var/www/html/wp-content/wp-content-themes.tar.gz

Step 4 : Change File Permissions

==> Check permission of files and directories and change user group ownership also if it is other than apache:www.

# chown -R apache:www /var/www/html/

# find /var/www -type d -exec sudo chmod 2775 {} \;

# find /var/www -type f -exec sudo chmod 0664 {} \;

DB Export and import :

Step 1 : Install wp-cli in each dev and prod servers

# curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# php wp-cli.phar –info

# chmod +x wp-cli.phar

# sudo mv wp-cli.phar /usr/local/bin/wp

==> Run following commands to export from Dev environment,

$ cd /var/www/html/

$ wp db export


==> Once we copied the .sql file to prod server run the following command to import the latest DB,

$ wp db import devopstree_jj-fb891a7.sql

==> Once we import the latest db, we should replace the url from dev to prod

$ wp search-replace  beta.dailywinkle.com www.devopstree.com

Sharing is caring!


I'm an IT professional having multiple years of experience in IT Infrastructure planning, System integrations, Project implementation, and delivery. DevOps Enthusiast skilled with broad ranges of technology adoption. Well versed with Cloud Computing and Application Service Offerings such as SaaS/PaaS/IaaS. Expert in aligning business goals, mission and process to architect innovative solutions and strategies.