Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to distinguish test environment from formal environment by setting system environment variables in PHP

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to distinguish between the test environment and the formal environment by setting system environment variables in PHP, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

First, introduction

Environment variables can be obtained in 1.PHP through the getenv () function and $_ ENV.

two。 Environment variables are stored in the system and do not change with the submission of the code

3. If the company has two test servers and formal servers, it is a good way to distinguish the test environment from the formal environment by means of environment variables.

4. Safe, don't worry about submission overwrite

Second, setting method

1. Open the etc/profile file: vim ~ / etc/profile

Add an environment variable export PHP_ENV= "test", and set the official server to = "prod"

In this way, you can do some different operations through the system environment variables, or there may be different database account passwords.

Reload after setting: source ~ / etc/profile

two。 Modify the php-fpm.conf file of PHP and set the PHP environment variable

Add at the bottom: Env [PHP _ ENV] = $PHP_ENV

Restart the PHP service, service php-fpm restart

3. What if getenv ('PHP_ENV') can't get the value?

It may be because php.ini does not load the $_ ENV variable definition by default. If you look at phpinfo () at this time, you will find that the environment variable we set is "no value"

Modify vim / etc/php/php.ini

Modified: variables_order:variables_order= "EGPCS"

Restart the PHP service

4. Check phpinfo (), or use the getenv () function to get variables

If it is not available, use $_ ENV; because the getenv function is no longer supported in version 7.

Thank you for reading this article carefully. I hope the article "how to distinguish the test environment from the formal environment in PHP by setting system environment variables" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report