Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Flexible Docker Images with PHP INI Environment Variables

    Flexible Docker Images with PHP INI Environment Variables

    December 7, 2024

    Flexible Docker Images with PHP INI Environment Variables

    I recently posted about Get Xdebug Working With Docker and PHP 8.4 to show you how easy it is to get an Xdebug connection working. In that tutorial, I hard-coded INI settings to keep the tutorial focused on setting up Xdebug. In a real application, you want your Docker images to be flexible so each developer can configure their own settings without affecting the image configuration.

    In this post, I’ll show you how to use environment variables to make your images super flexible. As of v8.3, PHP supports fallback values with the INI environment variable syntax, so we can really make our INI configuration clean.

    If you reference the previous tutorial, our xdebug.ini file looked like the following snippet:

    ; build/php/conf.d/xdebug.ini file
    [xdebug]
    xdebug.mode = debug
     
    xdebug.client_host = host.docker.internal
     
    ; Or use the host machine IP address:
    ; xdebug.client_host = 192.168.86.203
     
    xdebug.start_with_request = yes
    

    If another developer on your team doesn’t want to start Xdebug by default, they’d have to update the INI file, and either commit the change or just revert it. Gross.

    That is no way to live, especially since PHP now supports default fallback values in INI files. Before we get to that, we could also configure Xdebug directly with environment variables. The following is equivalent to our xdebug.ini file:

    services:
      app:
        build:
          context: .
          dockerfile: build/Dockerfile
          target: development
        ports:
          - "8080:80"
        volumes:
          - .:/srv/app
        environment:
          XDEBUG_CONFIG: "client_host=0.0.0.0 start_with_request=yes"
          XDEBUG_MODE: "debug,develop"
    

    If we moved the environment values to an unversioned ENV file, each developer could manage Xdebug settings locally. Another way to configure Xdebug is through INI like we initially did, but using envrionment variables:

    ; build/php/conf.d/xdebug.ini file
    [xdebug]
    xdebug.mode = ${PHP_XDEBUG_MODE:-debug,develop}
    
    xdebug.client_host = ${PHP_XDEBUG_CLIENT_HOST:-host.docker.internal}
    
    xdebug.start_with_request = ${PHP_XDEBUG_START_WITH_REQUEST:-trigger}
    

    I’ve prefixed these variables with PHP_ to avoid conflicts and quickly recognize which ENV values were meant to be used with INI configuration. For example, XDEBUG_MODE is reserved for Xdebug configuration directly, so if we want to configure it via our INI ENV variable we need a unique name.

    If you restart the Docker image, you can verify these settings by adding phpinfo(); exit; to the top of public/index.php or connect to the container:

    $ docker compose up --build -d
    $ docker compose exec app bash
    
    # In the container
    $ php -i | grep xdebug.start_with_request
    xdebug.start_with_request => trigger => trigger
    

    If you want to try customizing these values locally, add the following to your compose.yaml file:

    services:
      app:
        build:
          context: .
          dockerfile: build/Dockerfile
          target: development
        ports:
          - "8080:80"
        volumes:
          - .:/srv/app
    +    env_file:
    +      - .docker.env
    

    Then, create a .docker.env and .docker.env.example file in the root of your project. Add sensible defaults to the example file and add .docker.env to your .gitignore file. Here’s an example of the contents:

    PHP_XDEBUG_MODE=debug
    
    PHP_XDEBUG_CLIENT_HOST=host.docker.internal
    # Or use your computer's local network IP
    # PHP_XDEBUG_CLIENT_HOST=192.168.86.250
    
    PHP_XDEBUG_START_WITH_REQUEST=trigger
    

    You will need to recreate the container to see the updated ENV values, but once you do, you should see your ENV settings take effect:

    And that’s it, your INI settings are easy to modify without affecting the image build files.

    You can now make your Docker images flexible using environment variables with INI settings. I also showed you how to use Xdebug’s built-in environment variables to configure things if you prefer simplicity. However, not all settings can be set via the XDEBUG_CONFIG environment, so use the method of configuration that works best for you!


    The post Flexible Docker Images with PHP INI Environment Variables appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCreating An Effective Multistep Form For Better User Experience
    Next Article Add Approvals to Your Laravel Application

    Related Posts

    Machine Learning

    Salesforce AI Releases BLIP3-o: A Fully Open-Source Unified Multimodal Model Built with CLIP Embeddings and Flow Matching for Image Understanding and Generation

    May 16, 2025
    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Token Forge

    Development

    Mirai Variant Murdoc Botnet Exploits AVTECH IP Cameras and Huawei Routers

    Development

    User needs drive SERP evolution

    Development

    How to Build a Reusable useSearch Hook in React

    Development

    Highlights

    Development

    From Fiction to Fact: 7 Hacking Movies That Get Cybersecurity Right

    June 29, 2024

    There are numerous movies that envision futuristic scenarios, often portraying advanced technology within utopian or…

    Design Education Is Like a Marathon, Not a Sprint

    July 6, 2024

    Google: Over 57 Nation-State Threat Groups Using AI for Cyber Operations

    January 30, 2025

    Call of Duty: Black Ops 6 gets better as Treyarch reverts this controversial Zombies change

    January 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.