Excellent software and practical tutorials
existCentos7It is very simple to install PHP or the gd library extension of PHP.
Everything can be done throughyumDone.
yum install php-gd
The above command will install the gd library extension. Check the phpinfo page to see if GD is supported.
However, if the PHP version is installed manually, installing the GD extension is quite troublesome. After several big pits, I have found a simpler way.
Since a PHP version is required to coexist with the system's native version, your installation version must be compiled with the original version.
For example, if your version is php7.4.3, then your installation version source code should also be php7.4.3
Compile the php-gd extension. Most of the methods on the Internet are to install freetype, libpng, libjpeg, etc., which is relatively complicated. The compiled gd library does not yet include the jpeg and libpng extensions.
In fact, the tutorials on the Internet are misleading. The installation method is correct, but you must check under what version of PHP the extension is installed. The property directory of PHP7 has made some changes, which is different from the directory of versions before PHP7.
The gd extension of php7 supports png and zlib by default.
Here's how to install GD:
You can first install the relevant source package through yum.
yum install libpng libpng-devel libjpeg-turbo libjpeg-turbo-devel freetype freetype-devel gd
Enter the PHP source code directory, cd into the ext/gd directory, and use the phpize command to generate a cpnfiguer.
Or you can compile and reinstall PHP directly in the PHP source directory. If you reinstall, you need to make clean in the PHP source directory to clear the previously generated cpnfiguer
Install the gd extension in the gd directory:
cd php-7.4.3/ext/gd
Enter the installation command
./configure --enable-gd \ -–with-jpeg \ ––with-freetype \ make make install
Note: Here we do not need to specify the location of the specific gd, jpeg, freetype directories, and directly use the versions in the system directory.
The directories of png and zlib do not need to be rewritten, as gd has installed png and zlib by default.
After the code is installed, check phpinfo and you will find that the gd library has been installed ok. Of course, you need to restart the system or reload the PHP service.