How to Deploy Magento 2 To Production

- Magento 2

Magento 2 deployment to production

If you don’t have any exact strategy for deploying your new Magento 2 website to production, then you’ve come to the right place. Below, we provide general guidelines which will be helpful for everyone who wants to deploy Magento 2 to production. Please note that each Magento 2 store has its unique features and requirements, so it is recommended to deal with a specialist who can help you choose what additional steps are vital for your particular case.

'

How to deploy Magento 2 to production: General preparation

In the very beginning, you should prepare both development and production systems before starting Magento 2 deployment to production. The following preparations will help you avoid various problems and errors.

So, in your Magento 2 development system, the following preparations are fundamental:

  • Run tests to find out if your system in the development environment works as expected.
  • Then, you should pay attention to all custom code, since it has to be in source control.
  • The next step requires compiling code and generating static view files.
  • Now, you should perform two essential actions. First of all, archive your filesystem assets. Then, export the database of Magento 2.
  • The final step consists of transferring the aforementioned content to the Magento 2 production system.

When done with preparing the development system of Magento 2, get ready to make some changes to the production system:

  • First and foremost, you should create the Magento 2 deployment configuration.
  • Then, it is required to extract both filesystem and database assets from the archives you’ve made previously.
  • Another important aspect is setting filesystem permissions.
  • And don’t forget to test all possible facets of your Magento 2 installation. If something fails to work as expected, fix it before going further.
  • If everything is ok, you can point the DNS server to the Magento 2 production system.

How to deploy Magento 2 to production: The development system

If you don’t know what the development system is, then pay attention to the following section ot the article. Being a place where you can deploy code, the development system provides the ability to clean static files, reinstall or export database, compile code, remove temporary files unnecessary in production, or even archive your filesystem.

As for the best development practices, they include:

  • Using cron as a Magento filesystem owner.
  • Performing commands or install / uninstall Magento 2 as the same user.
  • Enabling developer mode via magento deploy:mode:set.
  • Cleaning cache.
  • Compiling code directories.
  • Setting up the robots.txt file.

How to deploy Magento 2 to production: Server checklist

Below, you will find a short production server checklist. The following steps provides the ability to deploy Magento 2 to production seamlessly. Make sure you’ve done as many as possible of the actions described below. Please note that your Magento 2 website could have some additional requirements, so consult with the specialists before going any further.

How to deploy Magento 2 to production: General guidelines

The following section of the article provides general guidelines for deploying your Magento 2 installation to production. Please note that the situation is the same as in case of the server checklist: you should consult with a Magento 2 specialists before going further, because your ecommerce website might require additional tasks to be performed.

  1. Start your Magento 2 deployment to production with copying development filesystem and database archives from the development system to the production system.
  2. Then, take your Magento 2 filesystem archive and extract it to an empty directory.
  3. The third step requires setting up a persistent storage, including media, cache, logs, session, etc.
  4. Now, you should enable maintenance mode and take the existing system offline. Use the magento maintenance:enable command. Please note that downtime stars after you perform this action.
  5. After enabling maintenance mode, you should install the Magento software. Choose a clean database or use the –cleanup-database option.
  6. When the Magento software is installed, it is necessary to import your existing database data utilized in the Magento 2 development system.
  7. Now, take an existing filesystem and put it to an archive location.
  8. Then, move it to the docroot of your Magento 2 instance.
  9. The next step requires changing to production mode. Thus, you should also set new filesystem permissions as well as ownership for production.
  10. Before finishing your Magento 2 deployment to production, don’t forget to test everything, because there might be some bugs or errors in the system.
  11. If everything is fine, you can switch DNS to your new server. That’s how you finish downtime.

Final Words

As a conclusion, we’d like to mention some best practices you can implement in production. You can accelerate HTTP traffic via Varnish. The dedicated guide is mentioned in the server checklist above.

Again, configure a web server’s virtual host in such a way it would be able to point to the pub directory of Magento 2 to prevent your production ecommerce store from running the Setup Wizard, System Upgrade, or Component Manager, if you haven’t done that yet.

And don’t forget to set up the robots.txt file, since it allows search engines to index your Magento 2 production website.

For further improvements check these articles:

'