Create ddev project

See here https://www.weeumson.com/posts/DDEV-for-Magento-2-local-dev/

# Make the directory and switch to it
mkdir m2-project && cd $_
 
# Initialize the project configuration (.ddev folder creation)
ddev config --project-type=magento2 --php-version=8.2 --docroot=pub --create-docroot --disable-settings-management

Configure a few DDEV things

Timezone + DB Port

For more local time stamps, we will add our timezone to the .ddev/config.yaml file, as well as a static Database port.

Insert the following 2 lines, substituting your timezone (Wiki of time zones here)

timezone: America/New_York
host_db_port: "3307"

Without the explicit DB port, the DB will have a random port every ddev start or ddev restart . This can be a good thing, but I prefer to set up my DB explorer once and be done with it.

Install deps

ddev get ddev/ddev-opensearch
ddev get ddev/ddev-cron 
ddev get ddev/ddev-redis-7  
ddev get b13/ddev-rabbitmq

Set PHP memlimit

nano .ddev/php/memlimit.ini

[PHP]
memory_limit = 2G

Add Cron hook

Add following to the file .ddev/config.cron.yaml

hooks:
  post-start:
    - exec: /var/www/html/bin/magento cron:install
 

Get grunt and livereload working

Create the file .ddev/docker-compose.livereload.yaml with the content

services:
  web:
    expose:
      - '35729'
    environment:
      - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILPIT_HTTP_PORT}:8025,35728:35729
      - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILPIT_HTTPS_PORT}:8025,35729:35729
 

Edit .ddev/config.yaml and add the following to the end of the file

hooks:
  post-start:
    - exec: "npm install -g grunt-cli"
    - exec: "npm install -g livereload"

Now we need to add the livereload.js script to magento. Edit app/etc/env.php and merge the following into the array.

    'system' => [
        'default' => [
            'design' => [
                'footer' => [
                    'absolute_footer' => '<script defer src="https://selby.ddev.site:35729/livereload.js?port=443"></script>'
                ]
            ]
        ]
    ]

Note: might need to go to Content > Design > Configuration > ThemeName > Footer and make sure “use default value” is clicked for Miscellaneous HTML. E.g

b2c694a2414c2d6031dcff23bccbb58e.png

Grunt commands

# Run watch which should start livereload
ddev exec grunt refresh && ddev exec grunt watch 
 
# Build css manually
 ddev exec grunt clean && ddev exec grunt exec:selbyluma && ddev exec grunt less:selbyluma

Run provisioner script

Adjust as needed

provision.sh

Re-enable ddev settings management

Unclear if this is actually needed. This, I believe, let’s ddev change things in app/etc/env.php.

ddev config --disable-settings-management=false