Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Set server environment variables per site #473

MartinPeverelli opened this issue Nov 24, 2017 · 0 comments

[Feature] Set server environment variables per site #473

MartinPeverelli opened this issue Nov 24, 2017 · 0 comments


Copy link

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:


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 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.

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

No branches or pull requests

1 participant