Tags:

The ultimate Magento development environment

Time is money and therefore every developer should strive for an optimal setup in which he can operate the fastest. Since I began with Magento in 2008 a lot has changed tool-wise and I am constantly improving to find the optimum Magento local development setup.

Chris / / last updated on

The perfect Tools

Now let's have a look at which software pieces do you need for fast and qualitative development of Magento Extensions:

  • PhpStorm: since many years now the state-of-the-art IDE for PHP, this software is worth every penny and is continually updated every few months
  • Magicento: the plugin that makes PhpStorm incredibly useful for Magento by providing auto-completion, automatically generating module structure and many more features.
  • PHP Inspections (EA Extended): also a plugin for PhpStorm that massively supports you in writing correct, clean and effective code. I basically use this in conjunction with the code sniffer and the mess detector (see below)
  • PhpCodesniffer in combination with Magento ECG Coding Standards
  • Php Mess Detector: easily find duplicate code contents before someone other will find it
  • Xdebug with code coverage: run directly in PhpStorm you will get visual feedback about your code coverage
  • While in the good old days you had the Magento installation completely directly on your local PC, then switched to a Vagrant box with Magento and now we arrived at the beautiful container techniques like Docker. I cannot emphasize enough how helpful Docker is in my daily routine, especially when switching between different clients or extension developments, Magento versions, etc.
  • modman: this tools was created by one of the Magento gurus to help maintaining magento modules in different installations – very helpful for testing in different PHP/Magento/.. versions
  • n98-magerun: every Magento developer always has to do some repeating stuff like cache-flush, resetting admin password, install specific version with sample data, etc.; this tool is absolutely unbeatable in these things.
  • ngrok is a ideal tool if you have to access your local environment from the outside (like e.g. give test links to your clients, access APIs from third-party-services and so on)
  • a MacBook Pro ;-)

Magento 1 Docker Setup

As mentioned above Docker is a massive help in easily setting up a local Magento development environment and also switching between different PHP or Magento versions. Below you will find my perfect docker-compose.yml that I use for each Magento project.

The setup has the following features:

  • The Magento Docker image is based on FrankenPHP which is based on the Caddy Webserver bundled together with PHP and boy it is lightening fast - I have never seen a faster development environment!
  • It uses Mailpit to test local email delivery. Mailpit is also perfect in analyzing the email compatibility for different email clients (and there are many!)

Now let's have a look at the Docker Compose file:

version: "3.4"

services:
  franken:
    build: ./frankenphp
    ports:
      - "80:80"
      - "443:443"
    links:
      - "mysql:mysql"
      - "cache:cache"
      - "mailhog:mailhog"
    volumes:
      - ../htdocs/:${WEBSERVER_DOCROOT}/htdocs
      - ../src/:${WEBSERVER_DOCROOT}/src:delegated
      - ../vendor/:${WEBSERVER_DOCROOT}/vendor
      - ./magento/local.xml:${WEBSERVER_DOCROOT}/htdocs/app/etc/local.xml:ro
    environment:
      MAGE_IS_DEVELOPER_MODE: "1"

  mysql:
    image: mariadb:10.6
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MARIADB_AUTO_UPGRADE: 1
    ports:
     - "3306"
    volumes:
      - /var/lib/mysql

  cache:
    image: redis:latest

  mailhog:
    image: axllent/mailpit
    ports:
      - "1025:1025"
      - "8025:8025"

ddev Environments with Magento

At the moment I am exploring ddev for all of my development environments as it offers a very, very easy and quick setup - also across different operating systems. This saves yourself a lot of time dealing with Docker containers and comes with a lot of pre-build images out of the box.

If you have a Magento or OpenMage project all you have to do is ddev config followed by a ddev start to launch a fully working local development environment including Xdebug, Mailpit and many more features within minutes!

Using ddev and Magerun

Next to ddev another indispensible tool is Magerun. As Magento 1 / OpenMage lacks a CLI tool this saves you a lot of clicking in the Magento backend and offers useful commands for e.g. for use cases like

  • resetting passwords,
  • generating PHPStorm IDE helper files,
  • activating maintenance mode
  • and many, many more.

In addition you can also easily add your own Magerun commands or use some of the community-provided ones.

In order to be able to call Magerun directly from your ddev host, we will create a custom ddev command for it.

Therefore all we have to do is create the file .ddev/commands/web/magerun in our Magento project folder with the following content:

#!/bin/bash

## Description: Execute n98-magerun
## Usage: magerun
## Example: "ddev magerun"

php -d error_reporting="E_ALL ^E_DEPRECATED" /usr/local/bin/n98-magerun.phar "$@"

Then in order to make the Magerun phar file available in the Docker container, we have to create the file .ddev/web-build/Dockerfile with this content:

RUN \
    curl -sS -o n98-magerun.phar https://files.magerun.net/n98-magerun.phar &&  \
    curl -sS -o n98-magerun.phar.sha256 https://files.magerun.net/sha256.php?file=n98-magerun.phar && \
    shasum -a 256 -c n98-magerun.phar.sha256 && \
    chmod +x n98-magerun.phar && \
    mv n98-magerun.phar /usr/local/bin/n98-magerun.phar

And that's it! Then you can call all Magerun commands directly from the host simply by typing ddev magerun.


Post Comments to "The ultimate Magento development environment"

Submit Comment

With the use of this comment form you agree to the saving and processing of your data by this website. More information about the processing of your data can be found in our privacy statement.
Your data will be transmitted securely via SSL.

Meine Magento Extension Bestseller