Home >Backend Development >PHP Tutorial >After win2003 iis integrates php, the environment variables cannot be read_PHP tutorial
Under normal circumstances, the page of phpinfo() can be displayed. Let’s start with the problems that arise after being able to display the page.
php problems will be displayed on the phpinfo() page.
First check whether the path of your php.ini is correct.
Q: I have configured the php.ini file, but why does it have no effect after restarting the server?
A: This problem mainly involves the following situations.
The first reason is that the php.ini file read by the system is inconsistent with the php.ini file you modified at the time
1. You can use the Configuration File of phpinfo() ( php.ini) Path option to check which php.ini
is being read by the current PHP server 2. If you want to change the file access location of php.ini, you can refer to the search order of php.ini, as follows Shown:
a) The location specified by the SAPI module (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)
b) HKEY_LOCAL_MACHINESOFTWAREPHPiniFilePath (Windows registry location)
c) PHPRC environment variable
d) Current working directory (for CLI)
) web server Directory (for SAPI module) or directory where PHP is located (other cases under Windows)
f) Windows directory (C:windows or C:winnt), or specified by the --with-config-file-path compile-time option Location
3. General approach: Set the PHPRC environment variable,
a) Operation: Right-click My Computer->Properties->Advanced->Environment Variables
b) Create a new environment variable under the system variables with "the variable name is PHPRC and the variable value is the file path of your php.ini file"
The second reason is: PHP did not find the corresponding Extension library
1. Check the location of the extension library found by PHP: You can see
in the extension_dir option of phpinfo() 2. Change the extension_dir file in php.ini
The third reason: Failure to completely restart IIS
1. Modifications to php.ini must be completely restarted to take effect, not just the current site.
2. Enter cmd, stop the server: net stop iisadmin; start the server: net start w3svc
Q: Why can’t my PHP activate the MySql extension library?
A: In PHP5.0 and above, MySQL is not enabled by default, so we need to activate it manually.
1. To run MySql in PHP, you must activate the php_mysql.dll dynamic link library in php.ini. You also need to access the MySQL client link library, the libmysql.dll file
2. Yes Activate the php_mysql.dll dynamic link library through the extension in php.ini; the libmysql.dll file must be placed in the Windows system path PATH to access it. You can copy libmysql.dll to the system32 directory, or in the PATH environment variable Add a new path.
3. Recommended approach: Set PATH to facilitate future PHP upgrades. Just add the folder where "libmysql.dll" is located after PATH in the system environment variable. Remember to separate them with ";" characters
4. [Case] Recently, the server cannot find the MySql extension library, causing the program to fail to run. Therefore, delete all files and reconfigure the PHP server. But in the end, when I installed MySql, I could not activate the MySql extension library.
The information found in phpinfo() is as follows:
PATH: c:php
PHPRC: C:php
extension_dir:c:phpext
In addition, I tested activating other libraries, such as msql, gd2, xml, and they can be displayed normally in phpinfo()
Proving that PHP can find the php_mysql.dll dynamic link library, and MySql Another condition for the operation is to query the MySQL client connection library, that is, the libmysql.dll file. It seems that the problem lies here.
I searched for the libmysql.dll file on the C drive and found that there was a file in the system32 and php folders. After making a backup, I tried to delete the libmysql.dll file in system32 and found that it was locked and could not be deleted. , but it can be renamed. I changed the name casually and restarted IIS, and the server ran normally.
Additional point: If the Configuration File (php.ini) Path is displayed as C:Windows
, it means that the php.ini file has not been read.
In addition, I found that when integrating php with IIS, there are two ways: ISAPI and CGI mode
In both ways, we can see the phpinfo page
But using ISAPI mode, the environment variables cannot be read, so the php.ini path set through the environment variable PHPRC cannot be found.
Just use CGI, so you don’t have to copy many files to the system file.