How to get system environment variables into PHP while running CLI & Apache2Handler?

前端 未结 4 516
梦如初夏
梦如初夏 2020-11-28 05:13

My system is Ubuntu and I have set my environment variables in /etc/environment.

If I\'m running PHP script using

4条回答
  •  萌比男神i
    2020-11-28 06:02

    Recently i wrote a library to get values from environment variables and parse to the PHP data types. This library can be used to parse environment variables to PHP data types (like the casting to integer, float, null, boolean), parse the complex data structures like a JSON string and more with the contribution of the commnunity.

    The library is available here: https://github.com/jpcercal/environment

    Put your environment variables into "/etc/environment" and "/etc/apache2/envvars", after restart your Apache Server and load your environment variables to operational system:

    # source /etc/environment
    # source /etc/apache2/envvars
    

    And to get the values from environment variable (independently of the environment CLI, Apache, Nginx, PHP Built-in Server and more) to do it:

    Enjoy it.

提交回复
热议问题