There are many approaches to duplicating and transferring a WordPress site. The best method to use depends on the tools available, content that needs to be transferred and the total size of that content.
If you want to know how to backup a WordPress site or how to make an exact copy for testing and developing, you can consider the following methods:
Copy WordPress Site Components
A regular WP install is usually broken down in 3 parts, the Main Install Files, Custom Content files and Database.
This method may require FTP access to the website server, which I recommend using FileZilla for.
Main WordPress Install
The main WP files and folders carry the version of the current WP website and consist of the following folders and files in your websites root folder.
- wp-includes/
- wp-admin/
- index.php
- wp-config.php - contains database information and general config.
- all other wp-*.php files
WP-Content Folder
This folder is responsible for all the custom content that is unique to your site, and is separated in the following 3 folders:
- themes - the current active them as well as other installed themes are stored in this folder.
- plugins - every WP plugin installed on your site is placed in here.
- uploads - uploaded images, whether for posts, pages or branding are usually stored in here.
In some cases, copying the wp-content/themes
folder (or only the active theme) and the wp-content/uploads
folder to the new WP install is all that's necessary from wp-content.
All plugins from the wp-content/plugins
folder can be installed from within the new WordPress admins plugin page, which is usually faster if transferring via FTP.
Database
Lastly, we have the database, which stores all of the sites content, from posts, pages, comments, saved plugin and theme settings and you name it.
Luckily, it is possible to transfer all the databases content without having to access it directly.
Tools -> Export -> All Content
and import the downloaded file into the target WP admin from Tools -> Import -> WordPress Export File
.Transfer WordPress Site via SSH
If you're having trouble with the above methods due to a sites large database or content files, using SSH may be a more preferred option.
To access your website via SSH, you would require a software like PuTTY, to then access both the active and the target server.
Copy WordPress Database
With SSH, log in to your websites root folder, where WP is installed, and issue this command; Replace the placeholders (in capital letters) with your database information, which you can get from your wp-config.php file:
mysqldump -hDB_HOST -uDB_USER -pDB_PASSWORD --single-transaction DB_NAME > any-file-name.sql
For example, the above command could look like this:
mysqldump -hlocalhost -uwebsite_admin -pmypassword2000 --single-transaction website_db > export.sql
If you are on the root of your website when issuing the above code, then the export.sql
file will also be on the root (http://www.your-website.com/export.sql). If you intend to import this into a different server, you would first need to log-in to the target server via SSH, and issue the following command to retrieve the export file:
wget http://www.your-website.com/export.sql
Importing Database via SSH
You can import the exported .sql
file into a new and preferably empty database with this command:
mysql -hDB_HOST -uDB_USER -pDB_PASSWORD DB_NAME < export-file-name.sql
The above command assumes that export-file-name.sql
is in the same directory as you are, when you issue it in SSH.
Duplicate Site into Subdirectory
A simple example of how you could copy a website from the root folder (e.g. public_html
) into a subfolder of your websites root folder (e.g. public_html/new-site
):
cp -R public_html public_html/new-site
Or, if you are logged into SSH as ROOT and want to copy a users content into another account within the server, you can use:
cp -R /home/username-original/public_html /home/username-target/public_html
Copy Site to another Server
The final scenario is if you want to move all your websites content to another server. To do that, we first tar
the content in your WP root folder:
tar -cvf content.tar public_html/*
Now, we SSH log-in to the target server to retrieve the content with wget
and then extract it with the following commands:
wget http://www.your-website.com/content.tar
tar -xvf content.tar
Conclusion
The above SSH commands can be used with other CMS systems, other than WordPress, of course. If you'd like more descriptions, examples or have suggestions / fixes, feel free to comment as always.
Said on Sep 1, 2015 by Tim -