Home >Backend Development >PHP Tutorial >How to Configure Environment Variables for PHP Applications Running on Apache?
Configuring Environment Variables for PHP Applications on Apache
Introduction:
Accessing environment variables is crucial for customizing PHP applications based on their runtime environment. If you're running a PHP application on Apache, you'll need to configure environment variables correctly to ensure its seamless operation.
Setting Environment Variables for Single Domains:
SetEnv VARIABLE_NAME variable_value
Replace VARIABLE_NAME with the name of the environment variable you want to define, and variable_value with its corresponding value.
Configuring Separate Environment Variables for Different Domains:
Example:
<VirtualHost hostname1.com:80> ... SetEnv DOMAIN_NAME hostname1.com ... </VirtualHost> <VirtualHost hostname2.com:80> ... SetEnv DOMAIN_NAME hostname2.com ... </VirtualHost>
Restart Apache and Test:
Once the configurations are made, restart your Apache server to apply the changes. You can now access the environment variables within your PHP scripts using getenv('VARIABLE_NAME').
The above is the detailed content of How to Configure Environment Variables for PHP Applications Running on Apache?. For more information, please follow other related articles on the PHP Chinese website!