Skip to content

[Feature] Set server environment variables per site #473

Description

@MartinPeverelli

Some sites or frameworks depend on server environment variables to be set on the server configs (at the Apache vhost or nginx.conf levels), and do not provide a way for those variables to be declared on the code.

A quick example of this, would be specific to my line of work: Magento.
A Magento application that hosts two websites needs for the server to have two variables set: MAGE_RUN_CODE and MAGE_RUN_TYPE. These variables are read on the index.php file and its the way the application knows what website to serve.
I imagine this is not an uncommon situation...

Currently, there is no way for me to set these environment variables with Valet without some ugly hack, or editing my index.php file to hardcode those values in.

My proposal is to create a .env.valet file at the root of the application ($sitePath), and have Valet load those for me.

Here is a sample file:

<?php

return [
    'website1' => [
        'MAGE_RUN_CODE' => 'usa',
        'MAGE_RUN_TYPE' => 'website',
    ],
    'website2' => [
        'MAGE_RUN_CODE' => 'arg',
        'MAGE_RUN_TYPE' => 'website',
    ],
];

The idea is quite simple: the file will be read by the Valet Driver, and if the top level key matches the requested site, then the key-value pairs inside will be loaded as server environment variables.

In the example above, when website1.dev is requested, then this will be loaded:

$_SERVER['MAGE_RUN_CODE`] === 'usa' // true
$_SERVER['MAGE_RUN_TYPE`] === 'website' // true

I've submitted a proposal for this feature, but I'm sure it could use further discussion. If its liked, then it would require a little documentation to explain the functionality and the .env.valet file structure.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions