← DevLog

5 min read

Every project, one way to start it

Magento shops, WordPress and Nuxt sites and our own platform on Postgres all run locally on DDEV. Why, what it took to make a laptop match production, and the traps that cost us a database.

Every project we work on runs locally on my laptop: Magento shops, WordPress and Nuxt sites, and Gunnie.ai, our own platform in TypeScript on Postgres. They use PHP 8.3, 8.4 and 8.5, and MariaDB, MySQL and Postgres. Every one of them starts with the same command:

ddev start

DDEV puts each project in its own set of Docker containers, with its own PHP version, database and search engine, and its own hostname ending in .test. They run side by side without getting in each other's way. Switching from one client to another takes seconds, not an afternoon.

Why not just install PHP

One PHP version on the laptop works until the second client is on a different one. Then you start switching versions by hand, and the shop you are not working on breaks quietly.

Old local stacks also leave things behind. In October every request to a local site took five seconds. All five were spent on DNS: a resolver file from an old Valet setup sent .test lookups to a service that no longer ran. DDEV only needs the hosts file. Deleting that one file fixed it.

Match production, and read it off the server

A local environment is only useful if it behaves like production. So the versions are pinned to what the production server actually runs, read from the server itself.

On one Magento platform the search engine was set to "latest" and had drifted to OpenSearch 3.6. Production ran 3.3.2. The database was on MariaDB 10.6 while production ran 11.4. Both are now pinned to the exact production version.

One trap here. I first tried to work out the search version from the Composer requirements, and got it wrong. Those constraints are about the PHP client library, not the server. A 2.x client talks to a 3.x server, which is what production had been doing all along. Ask the server, not the code.

Changing the search engine's major version also means a full reindex. On a catalogue of about 840,000 documents that took under eight minutes. Not a reason to put it off.

A new developer in three commands

On that same platform, getting started now looks like this:

git clone ...
ddev start
ddev bootstrap

The last one is a custom DDEV command. It handles the four things a repository cannot contain: the Composer credentials, the vendor directory, the Magento configuration file and the database. It asks for the secrets once and keeps them in a file that git ignores.

We tested it on a Windows laptop where the developer is not a local administrator. That turned up the parts no Mac user would ever see. DDEV could not write the hosts file, because the admin account it elevates to cannot reach the Linux side of WSL2. Those lines now go in by hand, and the guide says so.

Two bugs only showed up in a clean clone. Both were invisible on my own machine because of a setting I had and a new colleague would not:

  • DDEV runs the scripts in .ddev/web-entrypoint.d/ inside its own startup shell. An exit 0 in one of them ends that shell, and the container dies with only "web container exited" as the message.

  • DDEV's Magento project type writes its own configuration file on first start, with a random encryption key and none of your services. Against a real database that key decrypts nothing. disable_settings_management: true turns it off.

So test onboarding in a fresh copy, under a different project name. Not in the folder you have been working in for months.

A database dump is not harmless

Dumps strip customer data. They do not strip configuration. A copy of a production database carries the production endpoints for the ERP, the product information system and the payment provider. Start it on a laptop and that laptop talks to production.

The local setup now overrides each of those with a sandbox address after every import. Mail settings are deleted rather than changed, so Magento falls back to sendmail and DDEV catches every message. Nothing leaves the laptop by accident.

The traps

  • Renaming a project starts it on a new, empty database volume. We lost a database that way. Export first, then rename, then import.

  • With mutagen file sync on a Mac, a file written inside the container can take a moment to appear on the host. A file that "disappeared" right after a composer run usually has not. Check inside the container, or run ddev mutagen sync.

  • On a WordPress site the router sent no forwarded-protocol header, so WordPress built every asset URL with http and the browser blocked them. A local-only line in wp-config.php that sets HTTPS when the port is 443 fixes it. Remove the #ddev-generated marker first, or the next database import rewrites the file and drops your line.

  • Running Magento commands locally can rewrite the tracked config.php and switch off two-factor authentication for every environment you deploy to. Look at the diff before you commit.

What we would tell anyone setting this up

  • Pin every service version to production, and get the versions from the production server.

  • Make a fresh clone start with a few commands, and test that on a machine that is not yours.

  • Treat a production dump as live configuration. Override every outside connection after import.

  • Write down why things are set up the way they are in a README, not in a config file a tool may rewrite.

None of this is exciting. It is the reason a bug a client reports on Monday can be reproduced on a laptop by Monday afternoon.