Skip to content

feat: enhance PHP addon environment with DockerEnv() integration - #7651

Merged
rfay merged 2 commits into
ddev:mainfrom
rfay:20250923_rfay_php_addon_env
Sep 25, 2025
Merged

rfay merged 2 commits into
ddev:mainfrom
rfay:20250923_rfay_php_addon_env

Conversation

@rfay

@rfay rfay commented Sep 23, 2025

Copy link
Copy Markdown
Member

The Issue

Working on ddev-upsun, I discovered that PHP addons were using a limited set of hardcoded environment variables instead of the complete environment provided by DockerEnv(). This resulted in:

  • Empty port values instead of actual configured ports
  • Missing environment variables available to other DDEV components
  • Hardcoded DDEV_APPROOT instead of configurable app root

Most of all I needed DDEV_PRIMARY_URL

How This PR Solves The Issue

  • Replace manual environment variable creation with app.DockerEnv()
  • Use mergo library for proper map merging of addon-specific environment variables
  • Maintain backward compatibility for .ddev/.env. files
  • Preserve DDEV_VERBOSE functionality for verbose mode

This does change the signature of DockerEnv() but shouldn't do any damage that way.

Manual Testing Instructions

  1. Install a PHP addon that uses environment variables
  2. Verify addon has access to proper port numbers and URLs
  3. Test with custom .ddev/.env. files to ensure merging works
  4. Confirm verbose mode still adds DDEV_VERBOSE=true

Automated Testing Overview

No changes

Release/Deployment Notes

  • On release, ddev-upsun can have all these environment variable workarounds removed.

🤖 Generated with Claude Code

## The Issue

PHP addons were using a limited set of hardcoded environment variables instead of
the comprehensive environment provided by DockerEnv(). This resulted in:
- Empty port values instead of actual configured ports
- Missing environment variables available to other DDEV components
- Hardcoded DDEV_APPROOT instead of configurable app root

## How This PR Solves The Issue

- Replace manual environment variable creation with app.DockerEnv()
- Use mergo library for proper map merging of addon-specific environment variables
- Maintain backward compatibility for .ddev/.env.<addon-name> files
- Preserve DDEV_VERBOSE functionality for verbose mode

## Manual Testing Instructions

1. Install a PHP addon that uses environment variables
2. Verify addon has access to proper port numbers and URLs
3. Test with custom .ddev/.env.<addon-name> files to ensure merging works
4. Confirm verbose mode still adds DDEV_VERBOSE=true

## Automated Testing Overview

Existing tests for addon installation and PHP action processing should continue
to pass. The change is backward compatible and only enhances the available
environment variables.

## Release/Deployment Notes

This change enhances PHP addon capabilities by providing the full environment
variable set. No breaking changes expected as this only adds variables and
improves existing values.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@github-actions

github-actions Bot commented Sep 23, 2025 •

Copy link
Copy Markdown

@rfay
rfay marked this pull request as ready for review September 24, 2025 13:35
@rfay
rfay requested a review from a team as a code owner September 24, 2025 13:35
@rfay
rfay requested a review from stasadev September 24, 2025 13:35

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I tested it with:

post_install_actions:
  - |
    <?php
    var_dump($_ENV);

I confirm that $_ENV now contains many more env variables.
Overrides from .ddev/.env* work.
DDEV_VERBOSE is added with --verbose.

@rfay

rfay commented Sep 24, 2025

Copy link
Copy Markdown
Member Author

Nice testing approach, thanks!

@rfay
rfay merged commit b2b159e into ddev:main Sep 25, 2025
@rfay
rfay deleted the 20250923_rfay_php_addon_env branch September 25, 2025 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants