{"id":1722,"date":"2021-04-20T06:49:09","date_gmt":"2021-04-20T06:49:09","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/set-up-staging-environment-in-magento-2\/"},"modified":"2025-09-01T11:19:44","modified_gmt":"2025-09-01T05:49:44","slug":"set-up-staging-environment-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/set-up-staging-environment-in-magento-2\/","title":{"rendered":"How to Set Up Staging Environment in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento developers may be tempted to launch their online store, set up the initial configuration, and get going!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, it is very much likely that you may face some error, install a poor quality extension, or something may go wrong that will disrupt the store functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, it is essential to&nbsp;<em><strong>set up staging environment in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is like playing with fire for a Magento developer to perform tasks such as upgrade, migrate, or customize in live store rather than in the staging environment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Staging environment provides a near-production environment that includes a database, web server, and all the services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the staging area to see if, say, the upgrade process will go smoothly or not! It allows using both the front and backend of your site to see if everything is running properly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the whole staging environment after any modification,\u00a0<a href=\"https:\/\/meetanshi.com\/magento-upgrade-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">upgrading to latest Magento 2 version<\/a>, or\u00a0<a href=\"https:\/\/meetanshi.com\/magento-extension-installation-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">installing a Magento extension<\/a>. If everything works properly in the staging area of a primary store, then follow the same in your live site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you know how much necessary it is to set up staging environment in Magento 2, here\u2019s the exact method for the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just follow the below steps, and your staging area will be ready to execute.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Set Up Staging Environment in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are four main basic steps to set up the staging environment of your primary store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create Staging Sub Domain or Create Subfolder Under Your root Directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create Staging Database<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Copy Production Store<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Update Configuration in Database<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create Staging Sub Domain or Create Subfolder Under Your root Directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Setup a subdomain&nbsp;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Login to your hosting server(i.e., cPanel) for your domain, create a subdomain or create the subfolder under your root directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create Staging Database<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Setup a blank database<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>While we\u2019re still in the hosting server, we first have to set up a blank database for our staging store:<\/li>\n\n\n\n<li>Enter staging for the new database.<\/li>\n\n\n\n<li>For the Username, we\u2019ll enter staging too.<\/li>\n\n\n\n<li>Enter whatever you\u2019d like in the Password field.<\/li>\n\n\n\n<li>Assign ALL PRIVILEGES.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Copy Production Store<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Copy our production store over to the sub domain directory<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Copy the main store\u2019s Folders and Files.\n<ul class=\"wp-block-list\">\n<li>For example :<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">zip -r mtbackup21012021.zip app\/ bin\/ dev\/ downloads\/ generated\/ info\/ lib\/ phpserver\/ setup\/ update\/ vendor\/<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, we need to copy the data from the Main Site\u2019s database to our staging database. We\u2019ll do this from SSH as well.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mysqldump -u [database_user] -p [database_name] > backup_livestore.sql<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Now, you\u2019ll be prompted to enter the password for the user with privileges to the Main Site database, so type that in the password field. Make sure to&nbsp;<a href=\"https:\/\/meetanshi.com\/free-tools\">set up a strong password<\/a>.<\/li>\n\n\n\n<li>Press the Enter key.<\/li>\n\n\n\n<li>It can take a couple of seconds or a couple of minutes, depending on your database\u2019s size.<\/li>\n\n\n\n<li>Just wait until it finishes.<\/li>\n\n\n\n<li>Once it finishes, we need to import this data to our staging database:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mysql -p -u STAGING_DBUSER  STAGING_DBNAME  &lt; backup_livestore.sql<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You\u2019ll be prompted to enter a password; this time, it\u2019s for the user who has privileges for the staging database.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Update Configuration in Database<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Update the Unsecure&nbsp;and&nbsp;Secure&nbsp;URL for our&nbsp;staging&nbsp;store:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pass the below commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE core_config_data SET value = 'staging_url' WHERE path LIKE 'web\/unsecure\/base_url';<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE core_config_data SET value = 'staging_url' WHERE path LIKE 'web\/unsecure\/base_url';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here you go, once you set up the staging area, you can modify code, content as per your requirement without the fear of stopping the live site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, upgrading a Magento store is one of the most complex tasks of Magento. So, use the above steps to set up the staging environment and then upgrade your store safely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Still, if you find any difficulty while upgrading your store, Meetanshi\u2019s experienced and certified developers offer professional\u00a0<a href=\"https:\/\/meetanshi.com\/magento-upgrade-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento Upgrade Service<\/a>\u00a0to upgrade your store to the\u00a0latest Magento 2 without any data loss and zero downtime. You may also love to read our blog post on\u00a0<a href=\"https:\/\/meetanshi.com\/blog\/set-up-store-information-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">setting up store information in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you find any difficulty while setting up the staging area of your Magento store, do share that with us.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ll be happy to help you out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento developers may be tempted to launch their online store, set up the initial configuration, and get going! However, it is very much likely that&#8230;<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1722","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1722"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1722\/revisions"}],"predecessor-version":[{"id":21319,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1722\/revisions\/21319"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}