DEV Community

Matthias Andrasch
Matthias Andrasch

Posted on

6

Import WordPress site into local project via DDEV + BackWPup

What is a fast way to download a remote WordPress site to your local computer in order to run it in a local instance? I currently use the following way via DDEV and the free WordPress plugin BackWPup if I need to debug a site locally in a quick way.

1. Create a new project folder

2. Add .ddev/config.yaml file and change the name::



# DDEV project configuration

# Local website will be available via <name>.ddev.site
name: my-new-project
type: wordpress
docroot: ""
nfs_mount_enabled: false
mutagen_enabled: false

# WebServer settings
php_version: "8.1"
mariadb_version: "10.5"
webserver_type: nginx-fpm


Enter fullscreen mode Exit fullscreen mode

The name will later be used for your local websites URL, e.g. https://my-new-project.ddev.site.

3. Create the file .ddev/providers/backup.yaml, copy & paste the file content from this source:

https://github.com/mandrasch/ddev-pull-wp-scripts/blob/main/.ddev/providers/backup.yaml

This file does the magic of importing a backup zip file into the local instance. It is a collection of commands which import the database, copies files and replace the live sites url with the local URL in the local database. This script is possible because of the DDEV feature Hosting Provider Integration.

4. Create a backup on your remote site via BackWPup plugin

5. Download the backup file and save it as backup.zip in your local project folder

6. Run ddev start in your local project folder

7. Run ddev pull backup to start the import

Screenshot of terminal with ddev pull backup command

Screenshot final result CLI DDEV - success

8. Open the site via ddev launch

Happy (local) developing!

Bonus

If you want to control the child theme folder in git and don't sync / overwrite these files on ddev pull backup, change the childThemeFolderName: setting in .ddev/providers/backup.yaml.

Also add the following .gitignore in the root level of your project directory and adjust the child theme folder name to your child theme (last line).


Ignore all ...

/*

... but track specific files / folders:

General files

!.gitignore
!/README.md
!/LICENSE

DDEV config and provider script

!/.ddev
/.ddev/*
!/.ddev/config.yaml
!/.ddev/providers
/.ddev/providers/*
!/.ddev/providers/backup.yaml

Child theme:

!/wp-content
/wp-content/*
!/wp-content/themes
/wp-content/themes/*
!/wp-content/themes/twentytwentyone-child

Enter fullscreen mode Exit fullscreen mode




Troubleshooting

  • Mixed quotes like define("WP_SITEURL", 'https://example.com') can't be handled yet, please convert your wp-config.php to either single or double quotes

  • "Fatal error: Uncaught Error: Call to undefined function add_filter() in phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1296) : eval()'d code:182" - check your wp-config.php, maybe your webhosting provider added some incompatible add_filter(). Comment out these lines. Explaination: https://wordpress.org/documentation/article/configuring-automatic-background-updates/#configuration-via-filters

Read more

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more