Set Environment Variables for PHP Access in Apache
When developing PHP web applications that rely on environment variables, it's crucial to establish these variables correctly in Apache. Let's explore how to set them and configure unique values for each domain.
For each domain, modify the corresponding virtual host configuration file located in Apache's configuration directory. Once you have found the appropriate virtual host configuration, add the following line:
SetEnv VARIABLE_NAME variable_value
Replace VARIABLE_NAME with the name of the environment variable and variable_value with its desired value.
For example, if you want to set the BASE_URL environment variable with the value "https://example.com" for the example.com domain, you would add the following line to its virtual host configuration:
SetEnv BASE_URL https://example.com
Repeat this process for each environment variable you need to define. To ensure that these variables are accessible in your PHP application, use the getenv() function as follows:
<code class="php">$baseUrl = getenv('BASE_URL');</code>
The above is the detailed content of How to Set Environment Variables for PHP Access in Apache?. For more information, please follow other related articles on the PHP Chinese website!