The Best Solutions For Local Magento 2 Development (Apache/Nginx, PHP, MySQL stack on Windows and OS X)

php-mysql-local-server

In the following article, we shed light on the most popular solutions for local Magento 2 development. Below, you can find an official recommendation on how to create an optimal development environment as well as a bunch of alternative solutions. 

Optimal Development Environment

The official Magento documentation describes a typical software development flow as follows: 

  • Local dev machine;
  • QA/integration server; 
  • Preview server (optional); 
  • Production server.

 

However, it doesn’t matter whether you develop a new extension or contribute to the code: it is necessary to establish a Magento 2 development environment first. Depending on the created conditions, your future productivity and final results may vary a lot. Let’s take a look at what local development machine is the most suitable according to the official tips for local Magento 2 development. 

Prerequisites

Under a local development machine, we mean an environment where you develop and deploy your code, testing it against a running Magento app. As you might have already guessed, it is recommended to configure your local development machine as close to a production server as possible. Thus, you will work with near-real conditions with a better understanding of how your Magento 2 project would behave.

Another important moment is that you should always run the Magento application in the developer mode when it comes to your development machine. To enable this mode, run the following command:

Now, when you are familiar with the prerequisites of creating a local Magento 2 development environment, we can proceed to the first step – local Magento 2 installation.

Installation

The official documentation sheds light on the following two ways to install Magento 2 locally: Manual installation or Virtual Machine installation. Let’s explore both options.

Manual installation

Manual installation is recommended only if your local machine meets the system requirements of Magento 2. In this case, you can use the same steps as provided for the  Magento installation on a production server.

Virtual Machine installation

As for the alternative solution, it lets you avoid numerous step of the previous procedure. For instance, there is no need to install a local LAMP stack. You can use a Virtual Machine tool combined with a virtual environment tool. For instance, the official documentation recommends using VirtualBox in a pair with Vagrant or Docker. As a result, you can create reusable and shareable instances for the local Magento 2 development.

Configuration

According to the official Magento documentation, you can optimize your local development machine as follows:

  • Always use the latest supported version of PHP. Thus, you will essentially increase the performance of your local Magento 2 development environment.
  • Use Percona instead of your MySQL database.
  • Install and enable PHP OPcache to make your local Magento 2 development environment more coder-friendly.
  • Enable Xdebug only than you need it. Note that the feature is off by default since it requires a lot of memory and degrades performance.
  • If sample data is necessary, add it to your local Magento 2 development environment via composer or by cloning repositories.
  • The performance of your local frontend development can be increased by turning off CSS and JavaScript merging.
  • Also, don’t forget to check whether caching is turned on, which is the default behavior. According to the official recommendation, you should turn off page cache and block cache for local Magento 2 development. But you should enable them for testing.
  • Turn on opcache timestamp validation.

For further information, follow this link: Optimal Development Environment for Magento 2.

VirtualBox

VirtualBox is a general-purpose virtualizer targeted at server, desktop, and embedded use. You can streamline the solution for the following scenarios:

  • Running multiple operating systems simultaneously;
  • Simplified software installation – entire software configuration is shipped;
  • Testing;
  • Backup;
  • Infrastructure consolidation – hardware and electricity costs are decreased.

Thus, you can use VirtualBox to load multiple guest OSes under a single host operating system. The solution lets you start, stop or pause each guest independently within its own virtual machine. Note that it is possible to configure each virtual machine independently and run it under a choice of software-based or hardware-assisted virtualization. Of course, the underlying host hardware should support this scenario. 

It is also worth mentioning that host OS, guest OSs, and apps can communicate with each other. The same is about guest VMs. As a result, you get a flexible environment for your Local Magento 2 development. 

Docker

PHP 7 with Docker

Docker is a very powerful tool designed to simplify Magento 2 development. Being a set of coupled SaaS and PaaS products. It utilizes operating-system-level virtualization to let developers deliver software in packages called containers, which are hosted by Docker Engine. 

Although containers are isolated from each other – each bundles its software, libraries, and configuration files – they use well-defined channels to establish communication. Also, note that a single operating system kernel is utilized making containers more lightweight than virtual machines.

And these features perfectly suits Magento development providing programmers with extra flexibility, scalability, and agility.

The service offers both free and premium tiers, but before choosing any of them, we recommend you to pass a free course by Mark Shust, where he teaches how to setup a Magento 2 Development Environment with Docker. The author sheds light on how to standardize development environments across the entire team to install and manage configuration for a Magento project.

Setup a Magento 2 Development Environment with Docker

Mark Shust’s Docker Configuration for Magento

Vagrant

vargan local server

Vagrant is a free open-source software for creating virtual development environments. The tool is no longer tied to VirtualBox and it can now work with VMware and other virtualization software. Vagrant supports several server environments (like Amazon EC2, for instance). The tool is written in Ruby, but it also works in projects written in Python, PHP, Java, JavaScript, C#, and other programming languages. There is also native support for Docker containers in Vagrant. To add a libvirt support to Vagrant, you have to use a vagrant-libvirt plugin.

Get Vagrant

Valet+

Valet+ introduces a better way to setup your local environment for Magento 2 development and avoid Vagrant, Docker, and /etc/hosts file. Being a third-party fork of Laravel Valet, it adds advanced functionality making things even simpler and faster.

With Valet+, you enable your Mac to run Nginx in the background every time your machine starts. Next, It utilizes DnsMasq to proxy all requests on the *.test domain, pointing towards sites installed on your local machine.

As a result, Valet+ creates a blazing fast development environment, which is way more efficient than Vagrant or even Docker, providing a great alternative for those who want a flexible Magento 2 development environment at extreme speed.

The easiest way to install Magento 2 on macOS using Valet+

MAMP

mamp local server

MAMP is a bunch of technologies composed of free open-source and proprietary commercial solutions. Its name is an acronym of Mac OS X (but it also works for Windows); Apache; MySQL; and PHP, Python, and Perl. The solution is based on a similar software set for Linux called LAMP. Various “AMP” packages for different operating systems are available. Note that MAMP also works with different CMS programs. As a result, you can set up a local development environment for Magento 2. Get MAMP for free or purchase a Pro version that costs EUR 39.00.

Get MAMP

XAMPP

xampp local server

XAMPP is a free and open source cross-platform web server solution, which consists of Apache HTTP Server, MySQL database, and scripts interpreters written in the PHP and Perl. X means “cross-platforming”. The development tool allows programmers to test their projects on computers without any Internet access by creating a local Magento 2 development environment. In addition, XAMPP provides support for creating databases in SQLite and MySQL. You can download XAMPP for Windows, OS X, and Linux.

Get XAMPP

AMPPS

ampps local server

AMPPS is another software stack which enables a local Magento 2 development environment. The stack includes Apache, Mysql, MongoDB, PHP, Perl, Python, and auto-installer by Softaculous. These tools are enough for successful web-development. With AMPPS, you can develop websites from open source web apps or write your own code from scratch.

Get AMPPS

Native Nginx, PHP-FPM, MySQL and phpMyAdmin on OS X

Hit the link below to find out how to install Nginx, PHP-FPM, MySQL, and phpMyAdmin on OS X Mavericks or Yosemite in the most straightforward manner. Get rid of the web server/LAMP stack and replace it with PHP-FPM and Nginx as FastCGI implementation. Thus, you will create a flexible local Magento 2 development environment for your projects.

Nginx, PHP-FPM, MySQL, and phpMyAdmin on OS X

Bitnami

bitnami local server

With Bitnami, you will be able to discover, download and install open source software with ease. Bitnami Stacks exist in three different forms: native installers, virtual appliances, and cloud templates. There is also a Bitnami Cloud Hosting. It is a commercial service developed to manage Bitnami library applications in the cloud. And it can help you with local Magento 2 development.

Bitnami official site

Mongoose

mongoose local server

Mongoose is another web server for Web developers and designers, which is built on top of libmongoose embedded library. Libmongoose is developed to serve Web GUI on embedded devices; implement RPC frameworks, RESTful services; handle telemetry data exchange; and perform a lot of other tasks. Follow the link below for further information.

Mongoose official page

EasyPHP

EasyPHP local server

EasyPHP is a WAMP package which consists of PHP, Apache, MySQL, PhpMyAdmin, Xdebug, and other useful tools. To begin coding, you just need to download and install it on your machine. The admin page provides you with the ability to list the docroot and extensions; change the Apache port, max execution time, the timezone, error reporting and maximum upload file size; add/remove alias; manage modules, etc. You can use EasyPHP to streamline your local Magento 2 development efforts.

EasyPHP official site