How to install the gd Library in Centosphp extension mode

Source: Internet
Author: User
This article describes how to install the gd Library in Centosphp extension mode. For more information, see CentOS.

The second server of the website runs mainly Python/Ruby. sometimes it also needs to run a PHP script, so PHP is also installed, and the environment is Nginx + php-fpm, PHP is compiled and installed by source code, so it is minimized installation, and even the mysqli extension does not exist. Today, we need to use the GD library to find that there is no GD Library environment, so we need to install this extension. It is convenient and quick to compile dynamic loading separately to deal with a single extension. The installation process is also complicated. record this to help later users.

First of all, my PHP is compiled and installed by source code. For more information, see install PHP and php-fpm by compiling source code.

Install the gd pre-database freetype, javassrc, and libpng first.

1. freetype


Copy codeThe code is as follows:
Wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.bz2"
Tar jxvf freetype-2.4.0.tar.bz2
Cd freetype-2.4.0
./Configure -- prefix =/usr/local/freetype & make install

2. parse src


Copy codeThe code is as follows:
Wget http://www.ijg.org/files/jpegsrc.v9.tar.gz"
Tar zxvf jpegsrc.v9.tar.gz
Cd jpeg-9
CFLAGS = "-O3-fPIC"./configure -- prefix =/usr/local/jpeg & make install
Mkdir-p/usr/local/jpeg/include
Mkdir-p/usr/local/jpeg/lib
Mkdir-p/usr/local/jpeg/bin
Mkdir-p/usr/local/jpeg/man/man1

3. libpng


Copy codeThe code is as follows:
Wget "http://downloads.sourceforge.net/project/libpng/libpng12/1.2.50/libpng-1.2.50.tar.gz? R=http%3A%2F%2Fwww.libpng.org%2Fpub%2Fpng%2Flibpng.html & ts = 1376631135 & use_mirror = nchc"
Tar zxvf libpng-1.2.50.tar.gz
Cd libpng-1.2.50
CFLAGS = "-O3-fPIC"./configure -- prefix =/usr/local/libpng & make install

Next, you need to cd to the gd Directory of the php source code. Otherwise, an error like cannot find config. m4 will be reported.


Copy codeThe code is as follows:
Cd php-5.3.6
Cd ext
Cd gd

Then execute the command/usr/local/php/bin/phpize in this directory. When should I use phpize? When we need to add some modules and don't want to re-compile php, we can use phpize. My PHP is installed in the/usr/local/php/directory, which can be modified according to your personal situation.


Copy codeThe code is as follows:
/Usr/local/php/bin/phpize

Now you can compile and install it separately:


Copy codeThe code is as follows:
. /Configure -- with-php-configure =/usr/local/php/bin/php-config -- with-jpeg-dir =/usr/local/jpeg -- with-png-dir =/usr/local/libpng -- with-freetype-dir =/usr/local/freetype
Or
. /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

Modify the php. ini file and add a line of extension = gd. so under extension = php_zip.dll.

Restart Nginx and check whether the installation is successful. Run/usr/local/php/bin/php-m to check whether the gd module is successfully loaded.


Copy codeThe code is as follows:
Service nginx restart
/Usr/local/php/bin/php-m

Console list:


Copy codeThe code is as follows:
[Root @ nowamagic gd] #/usr/local/php/bin/php-m
[PHP Modules]
Core
Ctype
Date
Dom
Ereg
Fileinfo
Filter
Gd
......

The gd Library is successfully installed.

Next, restart php-fpm:


Copy codeThe code is as follows:
Killall php-fpm
/Usr/local/php/sbin/php-fpm

Phpinfo.

OK. the installation is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.