Table of Contents
1. When the php.exe global environment variable is not added, we need to run php in the following directory:
View php version information:
View php expansion module:
First step:
Second step:
Step Three:
Step Four:
2. Set environment variables for php’s getenv() and $_ENV() functions:
The first step: modify the php.ini file, the following code:
Step 3: Restart the computer and it will take effect! Setting global variables for php.exe does not require restarting the computer.
Home Backend Development PHP Problem How to set php environment variables

How to set php environment variables

Jul 10, 2021 am 09:16 AM

How to set php environment variables: 1. Run "D:\phpStudy\php\php-5.6.27-nts\"; 2. For php's "getenv()" and "$_ENV() ” function sets environment variables.

How to set php environment variables

The operating environment of this article: Windows 7 system, PHP version 5.6, DELL G3 computer

How to set php environment variables?

Set system variables and environment variables for php

See this Title, there are two questions, whether to set system environment variables for php.exe, or to set environment variables for programming languages ​​​​that can be called directly. Some people may be confused when talking about this, because we often see the first type, which is quite It is useful for setting shortcut keys for a certain command without having to go to the directory where the application is installed and then type the command. For example:

1. When the php.exe global environment variable is not added, we need to run php in the following directory:

D:\phpStudy\php\php-5.6.27-nts\
Copy after login

Note: This is my php.exe installation directory, yours may be different from mine, that doesn't matter.
For example,

View php version information:

php -v
Copy after login

View php expansion module:

php -m
Copy after login

How to set php environment variables

This is a very troublesome thing , I want to use the php command anywhere, then you should add php.exe to the global environment variable.
This is very simple. Most programs set global variables in the same way. Find the computer, right-click, and open the system control system panel. There is an advanced system setting on the left, click in and you can see it. Picture steps shown below:

First step:

How to set php environment variables

Second step:

How to set php environment variables

Step Three:

How to set php environment variables

Step Four:

How to set php environment variables

Just fill in the installation path of your software , the system will automatically recognize the executable files you are facing, .exe, .bat, .phar and other executable files, and then you can directly use php commands anywhere! Isn’t it great!

2. Set environment variables for php’s getenv() and $_ENV() functions:

I’m not done yet, I need Setting environment variables for PHP is the kind of environment variables that can be obtained directly using getenv() and $_ENV()! Then you need to read here. There are no online tutorials on this yet, and I figured it out myself.
Proceed in three steps:

The first step: modify the php.ini file, the following code:

variables_order = "EGPCS"
Copy after login

The default value is 'GPCS', which represents: GET, POST, COOKIE, ENV and SERVER, E stands for ENVIRONMENT, which means environment variables!

Second step:

Follow the previous steps, open the environment variable setting window:
How to set php environment variables
Set the environment variables you need here, such as database account password, etc. I've made a mosaic here, it's a must.

Step 3: Restart the computer and it will take effect! Setting global variables for php.exe does not require restarting the computer.

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

echo getenv('DB_HOST_NAME)
//或者 echo $_ENV('DB_HOST_NAME)
Copy after login

Is that enough! Try it now!

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set php environment variables. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the best practices for deduplication of PHP arrays What are the best practices for deduplication of PHP arrays Mar 03, 2025 pm 04:41 PM

What are the best practices for deduplication of PHP arrays

Can PHP array deduplication take advantage of key name uniqueness? Can PHP array deduplication take advantage of key name uniqueness? Mar 03, 2025 pm 04:51 PM

Can PHP array deduplication take advantage of key name uniqueness?

What Are the Latest PHP Coding Standards and Best Practices? What Are the Latest PHP Coding Standards and Best Practices? Mar 10, 2025 pm 06:16 PM

What Are the Latest PHP Coding Standards and Best Practices?

How Do I Work with PHP Extensions and PECL? How Do I Work with PHP Extensions and PECL? Mar 10, 2025 pm 06:12 PM

How Do I Work with PHP Extensions and PECL?

How to Implement message queues (RabbitMQ, Redis) in PHP? How to Implement message queues (RabbitMQ, Redis) in PHP? Mar 10, 2025 pm 06:15 PM

How to Implement message queues (RabbitMQ, Redis) in PHP?

What are the optimization techniques for deduplication of PHP arrays What are the optimization techniques for deduplication of PHP arrays Mar 03, 2025 pm 04:50 PM

What are the optimization techniques for deduplication of PHP arrays

Does PHP array deduplication need to be considered for performance losses? Does PHP array deduplication need to be considered for performance losses? Mar 03, 2025 pm 04:47 PM

Does PHP array deduplication need to be considered for performance losses?

How to Use Reflection to Analyze and Manipulate PHP Code? How to Use Reflection to Analyze and Manipulate PHP Code? Mar 10, 2025 pm 06:12 PM

How to Use Reflection to Analyze and Manipulate PHP Code?

See all articles