Articles

A quick look at the new Magento 2 setup system

magento 2 new setup system

Magento 2 is shipping with a new setup system instead of the traditional installation wizard. Let’s take a look at what it is all about.

Introduction

For those not familiar with the term “setup system”, it is the installation wizard Magento uses to setup the configuration files, check file permissions, database initialization and all the rest that is required to make sure Magento is properly installed.

magento 2 setup system readiness check

The readiness check in action

A long time into the development of Magento 2, the traditional installation wizard of Magento 1 (Mage_Install) was being used, but since 0.1.0-alpha89 the new setup system started to surface. Around 0.1.0-alpha95 it went “live”. All you have to do to see it in action is get the latest Magento 2 build from Github or install it via Composer.

This article contains personal observations and relies on the unfinished alpha preview of Magento 2 (0.1.0-alpha98). Contents might be subject to change. /disclaimer

Magento 2 installation redirect flow

For those wondering how Magento 2 determines whether the setup should be ran, below is an overview of what back-stepping through the execution trace reveals. In layman’s terms: if the local.xml file does not exist, redirect to the setup.

  • In index.php the application bootstrapper (Magento\Framework\App\Bootstrap is fed (->run($app)) with an HTTP application instance (Magento\Framework\App\Http sub-class of AppInterface).
  • The bootstrapper asserts (Bootstrap::assertInstalled()) whether the configuration directory (app/etc) contains a local.xml file.
  • If it does not exist, the bootstrap instance its error code is set to ERR_IS_INSTALLED and an exception is thrown.
  • This exception is caught in the run() method of the bootstrapper and then passed to the catchException() of the application which was supplied earlier. You can go for Cloudways’ Application Hosting for the easy installation process.
  • In Http its case, catchException() delegates to a whole lot of checks and one of them is checking whether the bootstrap instance its error code equals ERR_IS_INSTALLED.
  • If positive, the installer path is retrieved and the redirect is set up.

To some this might look overly complex and others might raise question marks why error flags and exceptions are alternately used for control flow. It probably boils down to a matter of taste, but if you have better insights please leave a comment at the bottom.

It uses Zend 2, AngularJS and Bootstrap

Don’t let those new fancy technologies distract you: “as soon as you are looking what is under the Magento framework, you are probably doing the wrong thing” is what Alan Kent has to say on the matter.

It is however nice to know that the Magento 2 developers aren’t sitting still and sometimes affording themselves a bit of playground to use new technologies. The setup system is backed by Zend 2 and thus the structure of the setup system its code base is quite different than the rest of Magento 2 which runs on top of Zend 1. Combine this with the fact that the frontend makes use of AngularJS and almost solely communicates with the backend in JSON and you can easily tell that the setup system is a completely distinct entity.

We are uncertain why they decided to throw in Bootstrap instead of the new Magento UI framework. Maybe because it has support for Angular or because it was the quickest tool for the job. Whether they continue to use Bootstrap or not, undoubtedly they will refresh the UI thusly that it matches the Magento brand its house style.

It is decoupled

magento 2 setup command line interface

CLI fans do not need to worry

A major change in the new setup system is that it is decoupled from the rest of the code base. Though it integrates with the Magento 2 code base due to the necessity of calling modules their install scripts, most of the code is custom written. For example, registering the admin user is done by a new custom database library within the setup its framework.

A plausible explanation as to why they choose to decouple the setup, is that in the final scenario this relatively tiny tool will conveniently hide away all the technical backlog — like interacting with Composer — behind a web interface. Experienced users will still be able to interact with the installer from a CLI.

Final words

We like the idea that the setup is getting decoupled and the usage of Zend 2 gives us a sparkle of hope that in some future the rest of the legacy Magento code base will be refreshed. We are mumbling something about setting priorities for Magento 2 overall, but understand that writing unit tests for the Magento 2 code base all day is a whole lot less fun than playing with AngularJS and Bootstrap.

Few things work the first time and it is thus no surprise that the new setup system is still a bit flaky. Clear documentation or a word from Magento what exactly the new setup system will entail is still missing. Maybe Magento is still figuring out the latter.

Subscribe Newsletter

Subscribe to get latest Magento news

40% Off for 4 Months on Magento Hosting + 30 Free Migration