Magento – Magento2 moving from staging to live site

deploymentdevelopmentmagento2staging

I have not found too much information on an efficient process for a rolling development of my site so I can add custom modules and other file changes on staging and then push those changes onto the live copy of my site with magento2.

In Magento 1.9 we just had a git clone of the files and git pulled all changes that were ready for the live site this obviously will not work in magento2 were my staging site is in developer mode and my live site is in production.

What is the best practice that involves the least live site downtime ?
(no downtime would be optimal if that is possible)

Best Answer

You can use ansible to automate the steps :

From a global point of view :

(Manage all your changes with setup/upgrade scripts)

  • backup database
  • toggle maintenance
  • disable crons
  • retrieve updated code source
  • set your shared folders
  • install composer dependencies
  • execute bin/magento setup:install with parameters
  • update magento env configuration for Redis / Varnish and ElasticSearch
  • upgrade with ./bin/magento setup:upgrade
  • build di with ./bin/magento setup:di:compile -vvv
  • flush cache ./bin/magento cache:clean
  • set magento mode ./bin/magento deploy:mode:set {{ m2site_mode }}
  • reindex ./bin/magento indexer:reindex
  • configure / enable crons

Adapt these steps with your needs.

The clue is to make to steps works for new environement or for existent environement.

You will have downtime if you have some setup script to execute. To minimize downtime, do these steps on a preproduction server, and copy all generated code to your production server. You can reindex data in background.