Optimal Development Environment
A typical software development flow is as follows:
Local dev machine > QA/integration server > Preview server(optional) > Production server
Whether you are writing a new Magento 2 extension or contributing to the code base, the first step for any developer is setting up a development environment. This article will guide you in setting up and optimizing your local development machine.
Local development machine
Your local development machine is where you develop and deploy your code to test it against a running Magento application. Its configuration should be as close to a production server as possible.
In your development machine, make sure you are running the Magento application in developer mode.
You can enable this mode with the command
bin/magento deploy:mode:set developer.
The following is a list of the different ways you can install Magento 2 locally:
- Manual installation
If you are developing on a local machine that meets the system requirements, you can follow the same steps as installing Magento on a production server.
Virtual Machine (VM) installation
Installing Magento 2 in a virtual environment allows you to run Magento 2 without the need to install a local LAMP stack.
A search for “magento developer box” in GitHub provides a list of unofficial virtual machines configured for Magento development.
The following is a list of optimizations you can make on your local development machine
- Magento recommends installing and using the latest supported version of PHP 7 to increase performance.
- Replace your MySQL database with Percona.
- Make sure you install and enable PHP OPcache.
- Xdebug is off by default. Enable this feature only when you need it because it requires a lot of memory and degrades performance.
xdebug.max_nesting_levelconfiguration needs to be set to 200 or greater for Magento. You can increase the memory available to PHP to get an increase in performance with Xdebug on.
- If you need sample data, you can install it using composer or by cloning repositories.
- Make sure caching is turned on (this is the default behavior). Generally, only page cache and block cache should be turned off for development and turned back on when testing.
- Opcache timestamp validation should always be on for development. Development is impossible with opcache on and revalidation off because any PHP modification would require a cache reset.