Never miss Magento tips, tricks, tutorials, and news.
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.
There are four main basic steps to set up the staging environment of your primary store.
Just follow the below steps, and your staging area will be ready to execute.
Update the Unsecure and Secure URL for our staging store:
Check the whole staging environment after any modification, upgrading to latest Magento 2 version, or installing a Magento extension. If everything works properly in the staging area of a primary store, then follow the same in your live site.
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.
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.
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
Still, if you find any difficulty while upgrading your store, Meetanshi’s experienced and certified developers offer professional Magento Upgrade Service to upgrade your store to the latest Magento 2 version without any data loss and zero downtime.
Copy our production store over to the sub domain directory
Create Staging Database
I’ll be happy to help you out.
- While we’re still in the hosting server, we first have to set up a blank database for our staging store:
- Enter staging for the new database.
- For the Username, we’ll enter staging too.
- Enter whatever you’d like in the Password field.
- Assign ALL PRIVILEGES.
Copy Production Store
If you find any difficulty while setting up the staging area of your Magento store, do share that with us.
- Copy the main store’s Folders and Files.
- For example :
zip –r mtbackup21012021.zip app/ bin/ dev/ downloads/ generated/ info/ lib/ phpserver/ setup/ update/ vendor/
- For example :
- Next, we need to copy the data from the Main Site’s database to our staging database. We’ll do this from SSH as well.
mysqldump –u [database_user] –p [database_name] > backup_livestore.sql
- Now, you’ll be prompted to enter the password for the user with privileges to the Main Site database, so type that in the password field.
- Press the Enter key.
- It can take a couple of seconds or a couple of minutes, depending on your database’s size.
- Just wait until it finishes.
- Once it finishes, we need to import this data to our staging database:
mysql –p –u STAGING_DBUSER STAGING_DBNAME < backup_livestore.sql
- You’ll be prompted to enter a password; this time, it’s for the user who has privileges for the staging database.
Update Configuration in Database
Login to your hosting server(i.e., cPanel) for your domain, create a subdomain or create the subfolder under your root directory.
Thank you for subscribing.
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’;
Setup a subdomain
Setup a blank database
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.
Therefore, it is essential to set up staging environment in Magento 2.
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.
The Staging environment provides a near-production environment that includes a database, web server, and all the services.
Pass the below commands:
Get Weekly Updates
Now that you know how much necessary it is to set up staging environment in Magento 2, here’s the exact method for the same.
Something went wrong.
Magento developers may be tempted to launch their online store, set up the initial configuration, and get going!