search
HomeBackend DevelopmentPHP ProblemDetailed explanation of how to set system variables in php

Detailed explanation of how to set system variables in php

Sep 29, 2020 am 10:18 AM
phpenvironment variablessystem variables

How to set system variables in php: first turn on the computer; then find "Advanced System Settings" in the control panel; then click "Environment Variables" in "System Properties"; finally add the variable value and save it .

Detailed explanation of how to set system variables in php

# Recommended: "

PHP Video Tutorial

When I see this title, I have 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 What we often see is the first one, which is equivalent to setting a shortcut key for a certain command without having to enter 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\

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

View php expansion module:

php -m

Detailed explanation of how to set system variables in php

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:

Detailed explanation of how to set system variables in php

Second step:

Detailed explanation of how to set system variables in php

Step Three:

Detailed explanation of how to set system variables in php

Step Four:

Detailed explanation of how to set system variables in php

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"

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:


Detailed explanation of how to set system variables in php 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)

Is that enough! Try it now!

The above is the detailed content of Detailed explanation of how to set system variables in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools