Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

intossh@gmail.com's avatar

.env - variable prefix

Hi, I deployed my Laravel app to shared hosting and encountered a problem with env variables. The provider only allows variables with 'PHP_' prefix due to security reasons. Is it possible or would it be possible to add to Laravel to set the prefix for these variables? For now I changed the Illuminate\Foundation\helpers.php file's method env() and added:

$value = getenv($key);
        if ($value === false) {
            $value = getenv("PHP_" . $key);
            if ($value === false)
                return value($default);
        }

It works, but it will be overwritten after composer update. I'm not sure if this is common approach for other hosting providers aswell, so if it would be useful to add to Laravel for the others. Thanks.

0 likes
2 replies
cklmercer's avatar
Level 15

You can create your own helpers.php file and override the getenv() function there. As long as you load your helpers file first, then Laravel will never register it's own, since all of the helpers are wrapped with if ( ! function_exists('function_name')).

See this thread for some details on overriding functions in Laravel's helpers.php file.

https://laracasts.com/discuss/channels/general-discussion/override-functions-in-supporthelpersphp

1 like

Please or to participate in this conversation.