This article is an extension to the article for Magento 1. For information about the capabilities of the staging environment, please read the Magento 1 article first.

Your staging environment shares resources (disk, CPU, mem) with your production site. If you want to do things such as automated load tests, it is recommended to order a development package instead, so your production site will not be affected.

How to make a copy of a live site

Setup your staging environment by following the steps.

It is strongly recommended to use separate databases for your staging environment, so using the staging environment will not interfere with the production data.

Step one: Copy your magento2 directory to a staging content directory

Step two: Recreate symlinks for the staging public directory

Step three: Create a staging database

Step four: Edit your di.xml and env.php to use MySQL and Redis databases separate from the production databases

Now change at least your MySQL database to staging and your Redis databases for cache and FPC to another one that is not in use by the production. (for example: 3 and 4)

Step five: Dump the production database into the staging database

Step six: Change the base URL’s of your staging environment

Now to use the staging environment, we need to change the base URL’s to use the ports for the staging environment. This way your site is accessible through the same URL’s as the production shop but will be using different ports. We change the HTTP port to 8888 and the HTTPS port to 8443.

**Please note the we often see conflicts when the unsecure and the secure Base-URLs are not the same. So either set both Base-URLs to HTTP -> 8888 or both URLs to HTTPS -> 8443. For example:


Warning! Changing the base URL’s before changing your MySQL database to your staging database will have impact on your production site.

Use the following command to change the ports of your staging shop, but use your own domains. You can do this for a single storefront or for all of them.
This way, if your live shop is, your staging environment will be accessible on

Change the base URL’s for a single storefront using Magerun

This implies you use SSL for your Hypernode. If you don’t, order an SSL certificate or use Lets Encrypt

Change the base URL’s for all storefronts using a script

If you have many storefronts, that all should be changed it’s easier to use our script to change the base URL’s of your staging environment.

To use this script:

Change the base URLS’ for all your storefronts via MySQL

Another easy way to change the base URLs of all your stores is by running the following database queries:

A big thank you to our partner Experius for providing these.

Manually change the base URL’s of your storefronts

If you want to set the base URL’s manually, check our documentation on changing your base URL’s for Magento 1. Do you have a Magento 2 shop, please check this article on changing base URL’s.

Step seven: Change all references in your staging directory

If your media directory is stored in /data/web/staging, make sure first not to overwrite this folder with a symlink

Keep in mind:

  • Re-deploy your static files (clean out pub/static, and deploy your static files
  • Find symlinks: find /data/web/magento2_staging -type l -exec ls -lsa {} \;
  • Grep for /data/web/public in your staging directory: grep -R '/data/web/public' /data/web/staging
  • Grep for /data/web/magento2 in your staging directory: grep -R '/data/web/magento2' /data/web/{staging,magento2_staging}
  • If you use Git submodules keep in mind that you should change the hardcoded paths and symlinks from /data/web/public to /data/web/staging to avoid collisions between the staging and the production environment.
  • Fix symlinks in your .modman dir that are still pointing to /data/web/public
  • Regenerate your sitemap as it may still contain links to your live site.
  • Change all custom links and references that are in your staging installation pointing to the production install.

Now you should be able to reach your Magento 2 staging environment on

For additional configuration and troubleshooting refer to the Magento 1 staging environment article

Cleanup and refresh

If you created a staging environment before on the same machine, you might want to do a resync of the content and the database or remove all staging components


To cleanup or uninstall your Magento installation use the following magerun2 command:

This will remove your Magento installation and drops the database as well.


To refresh your installation, run all steps again.
This will resync your files and dumps the production database into the staging.
All steps are the same, making it easy to recreate your environment.