I recently installed CentOS 5.3 version of Linux on a new testing server and started configuring all of the bells and whistles. I made some initial tweaks to Apache, MySQL, and PHP to set up my web server test environment. Everything seemed to be running smoothly until I happened to run an older PHP script I wrote to manipulate image files. The script resizes and renames image files in specified directories. Only one problem, the script was dying without a trace, no errors, nothing.
After going through some steps to debug the script I narrowed it down to the imagecreatefromjpeg function that was being called. I checked and double-checked my syntax, the variables, everything looked good. So then I ran the phpinfo function on the server and noticed something very odd, there was no listing for the GD library in there. Could it be that it was not installed?
I logged into the server and did a quick search with the following command:
[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
Sure enough there was not a GD module in sight. I am not sure why the GD library for PHP is not installed on CentOS 5 by default (although maybe I missed something during the OS install) but it is easily corrected with one of my favorite ways to update Linux, which is YUM.
Here is the command and some example output:
[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 checkDependencies 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 kTransaction 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!
Not too painful… Once that is complete all you need to do is to restart Apache with this command:
[root@srv]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
That’s it. Once that was done my script ran without issue.