How we can set environment variables in core PHP without using any library in Cpanel

Viewed 379

I want to store my credentials in a secure place and can use them as env variable in my file in cpanel. I don't want to use any library or composer method to do this. I have seen solutions for the same on web by using .htaccess file but didn't get proper syntax to do that. So, please help me to do so.

1 Answers

You can do like:

// Set the environment variable, NAME.
putenv('NAME="Robert Smith"');

// Retrieve the environment variable, NAME.
echo getenv('NAME');

// Unset the environment variable, NAME.
putenv('NAME');

Setting environment variables in an Apache configuration If you're using Apache as your web server, then you can use the SetEnv directive to set environment variables. The directive can be used in Apache's main server configuration, a virtual host configuration, a directory configuration, or an .htaccess file.

The directive takes a case-sensitive name and value, which must be quoted if it contains spaces. If no value is provided, the variable will be initialised to an empty string.

SetEnv NAME "Robert Smith"

Related