Install PHP-gd

2018-07-31 09:29:14    Jon    10473

 About GD

GD extension is an open source image processing library that provides a series of APIs for processing images so that it can be used to create charts, graphics, thumbnails, and other image processing operations. It supports common image formats like JPG, PNG, GIF, and so on, so we need to install libpng, jpegsrc, and freetype before installing the php-gd extension.


Note: Set the path according to your actual situation.



Install  freetype

wget http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.5.5.tar.gz
tar -xf freetype-2.5.5.tar.gz
cd freetype-2.5.5
./configure --prefix=/usr/local/freetype
make && make install

Install jpegsrc

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9
./configure --prefix=/usr/local/jpeg
make && make install

Install  libpng

wget http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.31/libpng-1.6.31.tar.gz
tar zxvf libpng-1.6.31.tar.gz 
cd libpng-1.6.31
./configure --prefix=/usr/local/libpng
make && make install


Linux

1. CentOS

Install GD

It doesn't require to compile php. Use phpize add the new extension. Do NOT forget to make clean.

 cd /data/php-5.6.14/ext/gd/
 make clean
 /usr/local/php/bin/phpize
 ./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype
 make && make install



Now gd.so is in the directory of /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/



Alter php.ini and add extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/gd.so to it.


Restart the service and  check php-gd.


2. Ubuntu

sudo apt-get install php5-gd 

Note: It is php-gd, not php5-gd.


Restart it and it should work.


Windows


Alter PHP configuration file php.ini:


Remove ";" from ; extension=php_gd2.dll 


Restart it and it should work.


ZSite8.0