Set system variables, environment variables for PHP

Source: Internet
Author: User

See this headline, there are two questions, is to set the system environment variable to the Php.exe, or to set the programming language to directly invoke the environment variable, say here some people may faint, because we often see is the first, is equivalent to a command to set shortcuts, do not go into the installation of the application directory and then hit the command. For example: 1, did not add php.exe Global environment variables, we run PHP needs in the following directory can be:

D:\phpStudy\php\php-5.6.27-nts\

Note: This is my Php.exe installed directory, you may not be the same as mine, it is not important.
For example, to view the PHP version information:

Php-v
To View the PHP expansion module:
Php-m

This is a very troublesome thing and I want to use PHP commands anywhere, so you should add php.exe to the Global environment variable.
This is very simple, most of the program is the same set global variables, find the computer, point right button, open the control system panel system, the left side of the advanced system settings, point to see the. Picture steps as follows: first step:

Step Two:

Step Three:

Fourth Step:

Fill in the installation path of your software, you will be able to automatically identify your face executable file,. exe,. Bat,.phar, etc. executable files, and then you can directly use the PHP command anywhere. Isn't it cool? 2. Set the environment variable for PHP getenv () and $_env () functions:

It's not over yet, I need to set the environment variable for PHP, which is the kind of environment variable that can be obtained directly with getenv () and $_env (). Then you need to see here, the online tutorial has not yet, I also grope out.
In three steps: The first step: Modify the php.ini file, the following code:

Variables_order = "Egpcs"

The default value is ' GPCs ', which means: Get, POST, COOKIE, ENV and server,e represent environment, meaning environment variables. Step Two:

Follow the previous steps to open the Environment variable Settings window:

Set up the environment variables you need here, such as the database account password, and so on. I played mosaic here, is necessary. Step Three: Restart the computer, and then it will take effect. Setting a global variable for Php.exe does not require you to restart your computer.

After the reboot, you can use it directly in the program. For example, in my PHP program. You can directly:

echo getenv (' Db_host_name)
//or Echo $_env (' Db_host_name ')

Is it OK. Try it quickly.

Reference Link: http://blog.csdn.net/zhezhebie/article/details/72734590

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.