Home > Article > Backend Development > What should I do if php cannot open the gd library?
Solution to the problem that php cannot open the gd library: 1. Find and open the php.ini configuration file; 2. Remove the comment symbol ";" in front of "extension_dir"; 3. Change its value to an ext file The absolute path of the folder is sufficient.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if php cannot open the gd library?
Solve the problem of invalid opening of gd library in PHP
I need to reinstall PHP recently. I have been using XAMPP before, basically I don’t need to configure it myself. , now you are ready to directly download the official original version of Apache and PHP, and slowly explore how to inherit the configuration by yourself.
The Apache version I downloaded is 2.2.25, and the PHP version is 5.4.19. After integrating Apache and PHP and configuring it (the PHP installation directory is: F:\php5.4.19), remember that PHP is not turned on by default. GD library support needs to be enabled by yourself. So I opened the PHP installation directory/php.ini configuration file and found the following content:
;extension=php_gd2.dll
According to the method found on the Internet, remove the symbol ";" in front of the comment, and then restart the Apache server. The result is that Still not working, I still cannot see any information related to the GD library through the phpinfo() function. I saw many articles on the Internet about "Opening the GD library in PHP". They all just said "remove the semicolon in front of xxx", and there was no further explanation. Facts have proved that just doing this is obviously not enough, at least the official zip version of PHP cannot be configured like this.
So I had to check the configuration content of php.ini myself, and finally found the following line:
;extension_dir = "ext"
Obviously, the extension_dir directive was commented out, causing php to connect to the folder of the extension library ext cannot be found, so it is naturally impossible to find php_gd2.dll in the extension library, and gd library support is naturally not enabled.
So, I tried my best to remove the comment symbol ";" in front of the extension_dir directive, and restarted the server again, but... it still didn't work. This is unscientific. Is there something wrong with the value "ext" of the extension_dir directive?
PHP official said that the default location of PHP5 search extension library is C:\php5, so I tried to follow the official statement and still left extension_dir commented out, and created a new php5 file under the C drive. folder, then copied php_gd2.dll into it, restarted the server again, and the result... still didn't work.
At this time, through the phpinfo() function, we found that when the extension_dir directive was not enabled in php.ini, the value displayed by extension_dir on phpinfo() was actually C:\php - Is this the official explanation? The documentation is also wrong, or has PHP 5.4 been changed and the official documentation has not been updated in time? I don’t care about the others for now. Let’s try C:\php first, so I rename php5 to php. Everything else remains as usual, then restart the server, and then check that the gd library has been opened through the phpinfo() function. ——This at least proves that in PHP 5.4.19, the default search location for extension libraries is C:\php.
Of course, as we all know, the extension_dir instruction supports absolute paths. I spent a long time on it, mainly to understand the function and impact of the extension_dir instruction.
Finally, remove the comment symbol ";" in front of extension_dir
, and then change its value to the absolute path of the ext folder. The detailed code is as follows:
extension_dir = "F:/php5.4.19/ext"
Summary As mentioned above, for the official version of PHP, to enable gd library support, you must not only remove the comment symbol before extension=php_gd2.dll, but also remove the comment symbol before the extension_dir directive, and modify its value accordingly. Of course, it is not just the gd library. If you need to open other PHP extension libraries, such as php_mysql and php_mysqli, the method is similar.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if php cannot open the gd library?. For more information, please follow other related articles on the PHP Chinese website!