在php中访问Env变量

How to access environment variables located in ~/.bash_profile from within PHP running with apache localhost (Mac)? I tried getenv() but no luck. Is there anything I need to change with php.ini?

Example from the PHP website:

<?php
    // Example use of getenv()
    $ip = getenv('REMOTE_ADDR');

    // Or simply use a Superglobal ($_SERVER or $_ENV)
    $ip = $_SERVER['REMOTE_ADDR'];

    // Safely get the value of an environment variable, ignoring whether 
    // or not it was set by a SAPI or has been changed with putenv
    $ip = getenv('REMOTE_ADDR', true) ?: getenv('REMOTE_ADDR')
?>

Use $_SERVER Variables and $_ENV to get all you need. Do an print_r of each of them to see what they contain.