How to pass system env vars to php in apache?

by aniya.jaskolski , in category: PHP General , 5 months ago

How to pass system env vars to php in apache?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , 5 months ago

@aniya.jaskolski 

To pass system environment variables to PHP in Apache, you can use the SetEnv directive in your Apache configuration file.

  1. Open your Apache configuration file (usually located at /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf).
  2. Add the following line to the configuration file to set the desired environment variable:
1
SetEnv VARIABLE_NAME variable_value


Replace VARIABLE_NAME with the name of the environment variable you want to pass and variable_value with the value you want to assign to it.

  1. Save and close the configuration file.
  2. Restart Apache to apply the changes:
1
sudo service apache2 restart


Now, you can access the environment variable in your PHP script using $_SERVER['VARIABLE_NAME'].