Import WordPress site into local project via DDEV + BackWPup
Tags: wordpress, ddev, docker, devops
Published: 2023-08-07 10:27:44

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](https://ddev.com/) and the free WordPress plugin [BackWPup](https://backwpup.de/) 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:`:**

```yaml
# 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
```
_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](https://ddev.readthedocs.io/en/latest/users/providers/)._

**4. Create a backup on your remote site via [BackWPup](https://de.wordpress.org/plugins/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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajqlrs5crrl5owzjm4rd.png)

![Screenshot final result CLI DDEV - success](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irbky0xpcknd172dyckp.png)

**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
```

### 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

- https://github.com/mandrasch/ddev-pull-wp-scripts
- https://my-ddev-lab.mandrasch.eu/tutorials/cms-and-frameworks/wordpress.html