Install GD Library For PHP5 On CentOS

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, September 17, 2008

Follow me on Twitter as @mattiasgeniar

Note: this article only applies if your current PHP version has been installed by yum. If you custom compiled it from source, this will not work.

Verify PHP as installed by yum

An easy task, using yum. First step, see if it’s already installed.

[root@srv]# rpm -qa | grep php
php-common-5.1.6-15.el5
php-cli-5.1.6-15.el5
php-5.1.6-15.el5
php-pdo-5.1.6-15.el5
php-mysql-5.1.6-15.el5

Install the GD library using yum

If the GD Library isn’t present in that list, it wasn’t installed on the server yet. Install it using yum.

[root@srv]# yum install php-gd
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
extras                    100% |====================| 1.1 kB    00:00
updates                 100% |====================|  951 B    00:00
base                      100% |====================| 1.1 kB    00:00
addons                  100% |====================|  951 B    00:00
Reading repository metadata in from local files
primary.xml.gz            100% |====================|  81 kB    00:00
########################################## 282/282
primary.xml.gz            100% |====================| 164 kB    00:00
########################################## 374/374
primary.xml.gz            100% |====================| 853 kB    00:00
########################################## 2458/2458
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-gd to pack into transaction set.
php-gd-5.1.6-20.el5_2.1.i 100% |====================|  17 kB    00:00
---> Package php-gd.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Running transaction check
--> Processing Dependency: php-common = 5.1.6-20.el5_2.1 for package: php-gd
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-common to pack into transaction set.
php-common-5.1.6-20.el5_2 100% |====================|  21 kB    00:00
---> Package php-common.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Running transaction check
--> Processing Dependency: php-common = 5.1.6-15.el5 for package: php
--> Processing Dependency: php-common = 5.1.6-15.el5 for package: php-pdo
--> Processing Dependency: php-common = 5.1.6-15.el5 for package: php-mysql
--> Processing Dependency: php-common = 5.1.6-15.el5 for package: php-cli
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-pdo to pack into transaction set.
php-pdo-5.1.6-20.el5_2.1. 100% |====================|  18 kB    00:00
---> Package php-pdo.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Downloading header for php-mysql to pack into transaction set.
php-mysql-5.1.6-20.el5_2. 100% |====================|  18 kB    00:00
---> Package php-mysql.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Downloading header for php-cli to pack into transaction set.
php-cli-5.1.6-20.el5_2.1. 100% |====================|  18 kB    00:00
---> Package php-cli.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Downloading header for php to pack into transaction set.
php-5.1.6-20.el5_2.1.i386 100% |====================|  19 kB    00:00
---> Package php.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Running transaction check

Dependencies Resolved

=================================
Package                 Arch       Version          Repository        Size
=================================
Installing:
php-gd                  i386       5.1.6-20.el5_2.1  updates           113 k
Updating for dependencies:
php                     i386       5.1.6-20.el5_2.1  updates           1.1 M
php-cli                 i386       5.1.6-20.el5_2.1  updates           2.1 M
php-common              i386       5.1.6-20.el5_2.1  updates           154 k
php-mysql               i386       5.1.6-20.el5_2.1  updates            84 k
php-pdo                 i386       5.1.6-20.el5_2.1  updates            62 k

Transaction Summary
=================================
Install      1 Package(s)
Update       5 Package(s)
Remove       0 Package(s)

Total download size: 3.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): php-pdo-5.1.6-20.e 100% |=========================|  62 kB    00:00
(2/6): php-common-5.1.6-2 100% |=========================| 154 kB    00:00
(3/6): php-gd-5.1.6-20.el 100% |=========================| 113 kB    00:00
(4/6): php-mysql-5.1.6-20 100% |=========================|  84 kB    00:00
(5/6): php-cli-5.1.6-20.e 100% |=========================| 2.1 MB    00:01
(6/6): php-5.1.6-20.el5_2 100% |=========================| 1.1 MB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating  : php-common                   ####################### [ 1/11]
Updating  : php-pdo                      ####################### [ 2/11]
Updating  : php-cli                      ####################### [ 3/11]
Installing: php-gd                       ####################### [ 4/11]
Updating  : php-mysql                    ####################### [ 5/11]
Updating  : php                          ####################### [ 6/11]
Cleanup   : php-pdo                      ####################### [ 7/11]
Cleanup   : php-common                   ####################### [ 8/11]
Cleanup   : php-mysql                    ####################### [ 9/11]
Cleanup   : php-cli                      ####################### [10/11]
Cleanup   : php                          ####################### [11/11]

Installed: php-gd.i386 0:5.1.6-20.el5_2.1
Dependency Updated: php.i386 0:5.1.6-20.el5_2.1 php-cli.i386 0:5.1.6-20.el5_2.1 php-common.i386 0:5.1.6-20.el5_2.1 php-mysql.i386 0:5.1.6-20.el5_2.1 php-pdo.i386 0:5.1.6-20.el5_2.1
Complete!

Easy going, isn’t it?

Restart Apache

Restart your apache, and you’re ready to rock.

[root@srv]# service httpd restart
Stopping httpd:                                            [  OK ]
Starting httpd:                                            [  OK ]

Simple as that!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.