Set up WordPress locally (Docker®) from a production backup
Warning: This article covers an advanced technical topic that uses a third-party application managed locally on your own device. GoDaddy cannot help you if you experience issues with the setup process (see our Statement of Support).
To set up a local Docker® container to run your production WordPress site locally, follow these steps:
- Download the backup you plan to use. You'll need the WordPress files (wp-content folder) and the SQL database (
.sql). - Prepare Docker:
- Create
docker-compose.ymlin the root directory of your project with the official WordPress Docker image:services: wordpress: image: wordpress restart: always ports: - 8080:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: exampleuser WORDPRESS_DB_PASSWORD: examplepass WORDPRESS_DB_NAME: exampledb volumes: - .:/var/www/html db: image: mysql:8.0 restart: always environment: MYSQL_DATABASE: exampledb MYSQL_USER: exampleuser MYSQL_PASSWORD: examplepass MYSQL_RANDOM_ROOT_PASSWORD: '1' volumes: - db:/var/lib/mysql volumes: wordpress: db:
- Create
- Start services:
docker-compose up -d
- Find the database table prefix from your site's current wp-config.php or extract it from the SQL file.
Note: wp_ is the default database table prefix. If your table prefix isn't wp_, find your table prefix and use that in your query. Example: wp_xufdzp_posts.
- Import the database
.sqlfile:cat mwp_db/your-db-file.sql | docker-compose exec -T db mysql -uexampleuser -pexamplepass exampledb
Required: Be sure to updateyour-db-file.sqlwith the name of the SQL file you downloaded in Step 1. - Change the
siteurlandhomevalues in thewp-optionstable with the valuehttp://localhost:8080.- You can do this with docker-compose exec:
docker-compose exec -T db mysql -uexampleuser -pexamplepass exampledb -e "UPDATE {your_db_prefix_here}_options SET option_value = 'http://localhost:8080' WHERE option_name IN ('siteurl','home');"Required: Be sure to updateyour_db_prefix_herewith your actual table prefix from Step 4.
- You can do this with docker-compose exec:
- Configure
wp-config.phpto support both local and production sites:- Replace
require_once(__DIR__.'/../configs/wp-config-hosting.php');with the code below:if(file_exists(__DIR__.'/../configs/wp-config-hosting.php')) { require_once(__DIR__.'/../configs/wp-config-hosting.php'); } // Local DB setup else { define('DB_NAME', 'exampledb'); define('DB_USER', 'exampleuser'); define('DB_PASSWORD', 'examplepass'); define('DB_HOST', 'db'); define('WP_DEBUG', true); $table_prefix = 'wp_your_prefix'; // }Required: Be sure to replacewp_your_prefixwith your actual table prefix from Step 4.
- Replace
- Create an
.htaccessfile with the following code:# BEGIN WordPress
RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress - Remove the
wp-content/mu-pluginsfolder and thewp-content/object-cache.phpfile. These contain hosting settings; removing them locally will not affect your production site. - Navigate to your local site with
http:localhost:8080. - You can create a Git repository with code changes, none of which impact your production site.
More info
- Set up CI/CD Deployments via GitHub Action
- You can find the official WordPress Docker image at Docker.com.