{"id":13561455,"url":"https://github.com/julienloizelet/ddev-m2","last_synced_at":"2025-04-03T17:30:59.185Z","repository":{"id":44450459,"uuid":"381315842","full_name":"julienloizelet/ddev-m2","owner":"julienloizelet","description":"A DDEV stack for Magento 2 development","archived":true,"fork":false,"pushed_at":"2023-03-15T10:20:59.000Z","size":135,"stargazers_count":15,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-04T13:37:30.184Z","etag":null,"topics":["ddev","development","magento2"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/julienloizelet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-29T09:51:22.000Z","updated_at":"2024-05-12T14:13:52.000Z","dependencies_parsed_at":"2024-01-14T03:47:35.207Z","dependency_job_id":"f93bf822-9f7f-4a0f-8f31-8afafaf514f3","html_url":"https://github.com/julienloizelet/ddev-m2","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienloizelet%2Fddev-m2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienloizelet%2Fddev-m2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienloizelet%2Fddev-m2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienloizelet%2Fddev-m2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/julienloizelet","download_url":"https://codeload.github.com/julienloizelet/ddev-m2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247046823,"owners_count":20874731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddev","development","magento2"],"created_at":"2024-08-01T13:00:56.821Z","updated_at":"2025-04-03T17:30:54.176Z","avatar_url":"https://github.com/julienloizelet.png","language":"Shell","funding_links":[],"categories":["Magento","Shell"],"sub_categories":[],"readme":"# DDEV stack for Magento 2\n\n[![Version](https://img.shields.io/github/v/release/julienloizelet/ddev-m2?include_prereleases)](https://github.com/julienloizelet/ddev-m2/releases)\n[![Magento 2 Installation](https://github.com/julienloizelet/ddev-m2/actions/workflows/installation.yml/badge.svg)](https://github.com/julienloizelet/ddev-m2/actions/workflows/installation.yml)\n\n\n\nThe purpose of this repo is to share my Magento 2 [DDEV](https://ddev.readthedocs.io/en/stable/) stack.\n\n## This project is unmaintained\n\nThis project is officially marked as unmaintained, since I am now using DDEV add-ons like: \n\n- [My tools add-on](https://github.com/julienloizelet/ddev-tools)\n- [Redis add-on](https://github.com/ddev/ddev-redis)\n- [Memcached add-on](https://github.com/ddev/ddev-memcached)\n- [Elasticsearch add-on](https://github.com/ddev/ddev-elasticsearch)\n- [Varnish add-on](https://github.com/ddev/ddev-varnish)\n\nIf you want to see how ddev add-ons can be used to test a Magento 2 module, take a look to my [GitHub action](https://github.com/julienloizelet/magento2-ddev-installation/) and their associated [workflow tests](https://github.com/julienloizelet/magento2-ddev-installation/tree/main/.github/workflows).\n\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**\n\n- [Quick start](#quick-start)\n  - [DDEV installation](#ddev-installation)\n  - [Prepare DDEV Magento 2 environment](#prepare-ddev-magento-2-environment)\n  - [Magento 2 installation](#magento-2-installation)\n  - [Set up Magento 2](#set-up-magento-2)\n  - [Configure Magento 2 for local development](#configure-magento-2-for-local-development)\n- [Usage](#usage)\n  - [Test your own module](#test-your-own-module)\n    - [Static tests](#static-tests)\n    - [Unit tests](#unit-tests)\n  - [Cron](#cron)\n  - [Varnish](#varnish)\n    - [Varnish debug](#varnish-debug)\n  - [Working with Mage2TV clean-cache](#working-with-mage2tv-clean-cache)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Quick start\n\n_We will suppose that you want to test on a Magento 2.4.3 instance. Change the version number if you prefer another\nrelease._\n\n### DDEV installation\n\nThis project is fully compatible with DDEV 1.21.6, and it is recommended to use this specific version.\nFor the DDEV installation, please follow the [official instructions](https://ddev.readthedocs.io/en/stable/#installation).\n\n### Prepare DDEV Magento 2 environment\n\nThe structure of the project will look like below.\n\n```\nm2-sources\n│   \n│ (Magento 2 sources installed with composer)    \n│\n└───.ddev\n    │   \n    │ (Cloned sources of this repo)\n```\n\n- Create an empty folder that will contain all necessary sources:\n```\nmkdir m2-sources\n```\n- Create an empty `.ddev` folder for DDEV and clone our pre-configured DDEV repo:\n\n```\nmkdir m2-sources/.ddev \u0026\u0026 cd m2-sources/.ddev \u0026\u0026 git clone git@github.com:julienloizelet/ddev-m2.git ./\n```\n- Copy some configurations file:\n\n```\ncp .ddev/config_overrides/config.m243.yaml .ddev/config.m243.yaml\n```\n- Launch DDEV\n\n```\ncd .ddev \u0026\u0026 ddev start\n```\nThis should take some times on the first launch as this will download all necessary docker images.\n\n\n### Magento 2 installation\nYou will need your Magento 2 credentials to install the source code.\n\n     ddev composer create --repository=https://repo.magento.com/ magento/project-community-edition:2.4.3\n\n\n### Set up Magento 2\n\n     ddev magento setup:install \\\n                           --base-url=https://m243.ddev.site \\\n                           --db-host=db \\\n                           --db-name=db \\\n                           --db-user=db \\\n                           --db-password=db \\\n                           --backend-frontname=admin \\\n                           --admin-firstname=admin \\\n                           --admin-lastname=admin \\\n                           --admin-email=admin@admin.com \\\n                           --admin-user=admin \\\n                           --admin-password=admin123 \\\n                           --language=en_US \\\n                           --currency=USD \\\n                           --timezone=America/Chicago \\\n                           --use-rewrites=1 \\\n                           --elasticsearch-host=elasticsearch\n\nThis should take ages.\n\n### Configure Magento 2 for local development\n\n    ddev magento config:set admin/security/password_is_forced 0\n    ddev magento config:set admin/security/password_lifetime 0\n    ddev magento module:disable Magento_TwoFactorAuth\n    ddev magento indexer:reindex\n    ddev magento c:c\n\n\n## Usage\n\n### Test your own module\n\nThere are at least two ways to handle the source code of a custom Magento 2 module:\n- use the `app/code` folder\n- use composer and its `vendor` folder\n\n\nPlease read [this post](https://gist.github.com/Vinai/a94f2500cc5694a258620bbd30692b87) from Vinai Kopp to have an \nidea of the pros and cons of each approach.\n\nAs I mainly develop extension as an \"extension vendor\" developer (and not a \"merchant\" developer), I chose the \ncomposer way. Furthermore, as explained in this [Yireo article](https://www.yireo.com/blog/2019-05-10-local-composer-development-with-magento2) (see the \"My approach: Use composer paths\" part), I am \nusing a composer local path that I will call `my-own-modules/yourVendorName-yourModuleName` and I put my module \nsources inside it.\n\nThus, the final structure of the project will look like below.\n\n```\nm2-sources\n│   \n│ (Magento 2 sources installed with composer)    \n│\n└───.ddev\n│   │   \n│   │ (Cloned sources of this repo)\n│   \n└───my-own-modules\n    │   \n    │\n    └───yourVendorName-yourModuleName\n       │   \n       │ (Sources of a module)\n         \n```\n\nYou can choose the better way for you, depending on your needs. But if you make the same choice as me, here is what \nyou can do:\n\n\n```\ncd m2-sources\nmkdir -p my-own-modules/yourVendorName-yourModuleName\ncd my-own-modules/yourVendorName-yourModuleName \ngit clone git@github.com:yourGithubName/yourGithubModule.git ./\nddev composer config repositories.yourVendorName-yourModuleName path my-own-modules/yourVendorName-yourModuleName/\nddev composer require yourComposerModuleName:@dev\nddev magento module:enable yourVendorName_yourModuleName\nddev magento setup:upgrade\nddev magento cache:flush\n```\n\n#### Static tests\n\nDuring development, you can run some static php tools to ensure quality code:\n\n- PHP Code Sniffer: `ddev phpcs my-own-modules/yourVendorName-yourModuleName`\n- PHP Mess Detector: `ddev phpmd my-own-modules/yourVendorName-yourModuleName`\n- PHP Stan: `ddev phpstan my-own-modules/yourVendorName-yourModuleName`\n\n#### Unit tests\n\nYou can also check unit tests: `ddev phpunit my-own-modules/yourVendorName-yourModuleName/Test/Unit`\n\n### Cron\n\nIf you want to simulate Magento 2 cron, run the following command in\na new terminal:\n\n     ddev cron\n\nTo stop the cron, you have to close your terminal.\n\nYou should find a `var/log/magento.cron.log` for debug.\n\n### Varnish\n\nFirst, you should configure your Magento 2 instance to use Varnish as cache: \n\n```\nddev magento config:set system/full_page_cache/caching_application 2\n```\n\nThen, you can add specific files for Varnish and restart:\n\n```\ncp .ddev/additional_docker_compose/docker-compose.varnish.yaml .ddev/docker-compose.varnish.yaml\ncp .ddev/custom_files/default.vcl .ddev/varnish/default.vcl\nddev restart\n```\n\nFinally, we need to change the ACL part for purge process:\n\n```\nddev replace-acl $(ddev find-ip ddev-router)\nddev reload-vcl\n```\n\n\nFor information, here are the differences between the back office generated `default.vcl` and the `default.vcl` I use: \n\n- I changed the probe url from `\"/pub/health_check.php\"` to `\"/health_check.php\"` as explained in the\n[official documentation](https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/cache/config-varnish-advanced.html?lang=en):\n\n```\n .probe = {\n    .url = \"/health_check.php\";\n    .timeout = 2s;\n    .interval = 5s;\n    .window = 10;\n    .threshold = 5;\n    }\n```\n\n\n- I added this part for Marketplace EQP Varnish test simulation as explained in the [official documentation](https://devdocs.magento.com/marketplace/sellers/installation-and-varnish-tests.html#additional-magento-configuration):\n\n```\nif (resp.http.x-varnish ~ \" \") {\n           set resp.http.X-EQP-Cache = \"HIT\";\n       } else {\n           set resp.http.X-EQP-Cache = \"MISS\";\n}\n```\n\n\n#### Varnish debug\n\nTo see if purge works, you can do : \n\n```\nddev exec -s varnish varnishlog -g request -q \\'ReqMethod eq \"PURGE\"\\'\n```\n\nAnd then, from another terminal, flush the cache :\n\n```\nddev magento cache:flush\n```\n\nYou should see in the log the following content: \n\n```\nVCL_call       RECV\nVCL_acl        MATCH purge \"your-ddev-router-ip\"\nVCL_return     synth\nVCL_call       HASH\nVCL_return     lookup\nRespProtocol   HTTP/1.1\nRespStatus     200\nRespReason     Purged\n```\n\n### Working with Mage2TV clean-cache\n\nThe Mage2TV clean-cache is a developer tool that automatically cleans the cache when necessary.\n\n```\n\n# Install\nddev composer require --dev mage2tv/magento-cache-clean\n# In your project create the var/cache-clean-config.json by running:\nddev exec php /var/www/html/vendor/mage2tv/magento-cache-clean/bin/generate-cache-clean-config.php\n# Run to start watching\nddev exec node /var/www/html/vendor/mage2tv/magento-cache-clean/bin/cache-clean.js --watch\n```\n\nYou should add some alias in your `.bash_aliases` for example :\n\n```\ncache-clean.js () {\nddev exec php /var/www/html/vendor/mage2tv/magento-cache-clean/bin/generate-cache-clean-config.php\nddev exec node /var/www/html/vendor/mage2tv/magento-cache-clean/bin/cache-clean.js \"$@\"\n}\n```\nWith this alias, you just have to run `cache-clean.js --watch` in your Magento 2 folder.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienloizelet%2Fddev-m2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulienloizelet%2Fddev-m2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienloizelet%2Fddev-m2/lists"}