How to Set Up Staging Environment in Magento 2

Steps to Set Up Staging Environment in Magento 2

Follow the following steps to Set Up Staging Environment in Magento 2:

  • Create Staging Sub Domain or Create Subfolder Under Your root Directory
  • Create Staging Database
  • Copy Production Store
  • Update Configuration in Database

Create Staging Sub Domain or Create Subfolder Under Your root Directory

Sign in to your hosting server to set up your domain, create the subdomain or subfolder under the root directory.

Create Staging Database

  • Create a blank database for the staging store.
  • Set the username for the database.
  • Set the password for the database.
  • Assign ALL PRIVILEGES for the database.

Copy Production Store

  • Copy the production store in the subdomain directory.
  • You can copy the files and folders of the store by command.
zip -r mtbackup21012021.zip app/ bin/ dev/ downloads/ generated/ info/ lib/ phpserver/ setup/ update/ vendor/
  • By SSH now we will copy the data of the database to our staging database.
mysqldump -u [database_user] -p [database_name] > db_name.sql
  • Enter the password in the field of Password. 
  • Now press the Enter key, it will take some time according to your database size.
  • When it is finished, import the data into our staging database.
mysql -p -u STAGING_DBUSER STAGING_DBNAME < db_name.sql

Update Configuration in Database

  • Now update the secure and unsecure URL in the database for the staging store
  • Run the following queries,
SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';
UPDATE core_config_data SET value = 'staging_url' WHERE path LIKE 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'staging_url' WHERE path LIKE 'web/secure/base_url';

If you are looking for Magento Developers, visit Magento Developer Agency.
Related Products