Back up a WordPress site (files and database)
At the end you will have a complete copy of the site on your computer: every file in the WordPress folder including wp-config.php, plus an SQL export of the database, checked and stored in more than one place.
What you need before step 1
Applies to: Self-hosted WordPress (WordPress.org software) on any host with SFTP or a file manager, and phpMyAdmin or SSH
Admin roles you need
- SFTP/FTP login or hosting control panel access to the site's files
- Database access: phpMyAdmin through the control panel, or SSH with WP-CLI or mysqldump
Licences
None needed.
Install instructions
https://make.wordpress.org/cli/handbook/guides/installing/Our step-by-step →Install stepsAlso have ready
- An SFTP or FTP client (WordPress's backup page mentions FTP clients and WinSCP), or your host's file manager
- Enough free space on your computer for the whole site
- The database name from wp-config.php (the DB_NAME line)
- A second storage location for the copy (cloud storage, external disk)
8 steps
- 1
Connect to the site files
Where: Your SFTP client on your PC (new site or new connection dialog)Set Protocol to SFTP, enter your host (for example
contoso.com), port 22 and your SFTP username and password from your hosting account, then select Connect. Browse to the WordPress folder: the one containingwp-config.php,wp-contentandwp-admin(oftenpublic_html).You should see: The remote pane lists wp-admin, wp-content, wp-includes, wp-config.php and .htaccess. - 2
Download every file
Where: Your SFTP client: remote (server) paneCreate an empty local folder such as
contoso-backup-filesin the left pane. Select everything in the WordPress folder, includingwp-config.phpand.htaccess(turn on the client's option to show hidden files so dot-files appear), right-click and select Download. If you have no SFTP access, use your host's file manager to compress the WordPress folder into a zip and download that instead.You should see: The transfer queue empties with no failed transfers, and the local folder contains wp-content (themes, plugins, uploads) and wp-config.php. - 3
Option A: export the database with WP-CLI
Where: SSH session to the web server, in the WordPress folderRun
wp db export. With no filename it names the file{dbname}-{Y-m-d}-{random-hash}.sql; giving a name makes it easier to find. Then download the .sql file with SFTP.cd /var/www/contoso.com/public_html wp db export contoso-backup.sqlYou should see: Success: Exported to 'contoso-backup.sql'. - 4
Option B: export the database with mysqldump
Where: SSH session to the web serverUse the database host, user and name from
wp-config.php. Enter the database password when prompted. The second form compresses the file with gzip.mysqldump --add-drop-table -h localhost -u contoso_user -p contoso_wp > contoso-backup.sql mysqldump --add-drop-table -h localhost -u contoso_user -p contoso_wp | gzip > contoso-backup.sql.gzYou should see: The command returns to the prompt and the .sql (or .sql.gz) file has a non-zero size. - 5
Option C: export the database with phpMyAdmin
Where: Hosting control panel (for example cPanel > Databases > phpMyAdmin)Select your WordPress database in the left pane. Select the Export tab. Choose Custom, make sure the format is SQL, tick Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement, choose gzipped compression if you want a smaller file, then select Go. (Quick export with SQL format also works.) WordPress notes phpMyAdmin cannot handle large databases; use Option A or B for those.
You should see: Your browser downloads a .sql or .sql.gz file named after the database. - 6
Keep wp-config.php safe and separate
Where: Your PCwp-config.phpholds the database name, user and password and the security keys. You downloaded it with the files; keep a second copy with the database export, and store the backup somewhere private because of the credentials it contains.You should see: You have wp-config.php in both the files backup and alongside the SQL export. - 7
Store copies in more than one place
Where: Your PC, cloud storage, external diskZip the files folder and the SQL export together and name the archive with the date. WordPress recommends keeping at least three backups in different locations, for example your host, cloud storage and your computer.
You should see: The dated archive exists in at least two places besides the web server. - 8
Test the backup
Where: Your PC, then a test or local WordPress environmentOpen the archive and confirm
wp-content/uploadscontains your media and the SQL file opens in a text editor and containsCREATE TABLElines for your tables (prefixwp_or the$table_prefixin wp-config.php). Ideally restore it to a staging or local site: copy the files back, import the SQL, update wp-config.php if the database details differ, and check the site loads.You should see: The test site loads with your pages, media and settings.
Expert tips
wp db export runs mysqldump and passes extra arguments to it, so on an InnoDB database add --single-transaction (wp db export backup.sql --single-transaction) to get a consistent snapshot without locking a busy shop or membership site.
A .sql file or zip left in public_html can be downloaded by anyone who guesses the name, and it contains every user record and password hash. Write it outside the web root (for example wp db export ~/backups/site.sql) or move it off the server straight away.
WordPress recommends keeping at least three to five recent backups in different places and on different media, such as the host, cloud storage and a local computer. A backup that exists only on the same server dies with that server or hosting account.
Without a file name, wp db export writes {dbname}-{Y-m-d}-{random-hash}.sql. Add --porcelain to print only the file name for scripts, or use wp db export - to stream to standard output and pipe it to gzip.
WordPress says to back up the database regularly and always before an upgrade. Treat a migration, a search-replace or a plugin update the same way: take a fresh export minutes before, so the restore point matches the moment you started.
How to confirm it worked
The local files folder size is close to the size your host reports for the site, and includes wp-content/uploads, wp-content/themes and wp-content/plugins.
The SQL file contains CREATE TABLE statements for every table in the database (compare with the table list in phpMyAdmin, or
wp db tables).A restore to a test site loads correctly.
How to reverse it
Taking a backup does not change the live site, so there is nothing to undo. Delete any .sql export left in the web folder on the server once it is downloaded, because it should not be publicly reachable.
Errors you might see
phpMyAdmin export times out or the file is incompleteCause: WordPress notes phpMyAdmin cannot handle large databases.
Fix: Export with wp db export or mysqldump over SSH instead.
.htaccess or other dot-files missing from the downloadCause: The SFTP client hides files starting with a dot.
Fix: Turn on the option to show hidden files in your SFTP client, then download again.
cPanel full backup cannot be restored through cPanelCause: WordPress notes cPanel full backups are strictly for archival purposes and cannot be restored via cPanel.
Fix: Use a database export plus a files download as described here.
mysqldump: Got error: 1045: Access denied for userCause: Wrong database user, password or host.
Fix: Copy DB_USER, DB_PASSWORD and DB_HOST exactly from wp-config.php.
Questions
How often should I back up WordPress?
WordPress suggests weekly for small sites with few posts, daily for busy sites, and always before an upgrade.
Does a database export include my images?
No. Uploads, themes and plugins are files and must be backed up separately.
In what order do I restore?
Restore the files first, then import the database, then update wp-config.php if the database credentials changed.
Can I use a backup plugin instead?
Yes. Most hosts also provide backup tools. A manual backup is still a useful check that the process works.
Official sources
Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.
