Managed Hosting for WordPress Help

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:

  1. Download the backup you plan to use. You'll need the WordPress files (wp-content folder) and the SQL database (.sql).
  2. Prepare Docker:
    • Create docker-compose.yml in 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:
  3. Start services:
    docker-compose up -d
  4. 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.
  5. Import the database .sql file:
    cat mwp_db/your-db-file.sql | docker-compose exec -T db mysql -uexampleuser -pexamplepass exampledb
    Required: Be sure to update your-db-file.sql with the name of the SQL file you downloaded in Step 1.
  6. Change the siteurl and home values in the wp-options table with the value http://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 update your_db_prefix_here with your actual table prefix from Step 4.
  7. Configure wp-config.php to 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 replace wp_your_prefix with your actual table prefix from Step 4.
  8. Create an .htaccess file 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
  9. Remove the wp-content/mu-plugins folder and the wp-content/object-cache.php file. These contain hosting settings; removing them locally will not affect your production site.
  10. Navigate to your local site with http:localhost:8080.
  11. You can create a Git repository with code changes, none of which impact your production site.

More info

Share this article