Update PHP from the command line with YUM

Posted in PHP -

It is important to keep software up to date on your computer and web servers. I manage a few webservers which run Apache/PHP/MySQL on CentOS, a Red Hat Enterprise Linux derivitive, and use YUM to install software and keep it up to date. This post looks how you would just do an update to PHP using YUM on CentOS.

You need to run the following command as either the root user, or by using the "sudo" command. Updating PHP is as simple as issuing the command below. This will also update all the dependent packages, i.e. the extensions you have installed, should they need to be.

yum update php

This then scans for updates and the following example output shows what happened on one of my development machines after running the above command:

Loading "installonlyn" plugin
Setting up Update Process
Setting up repositories
Reading repository metadata in from local files
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package php.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Running transaction check
--> Processing Dependency: php-cli = 5.1.6-20.el5_2.1 for package: php
--> Processing Dependency: php-common = 5.1.6-20.el5_2.1 for package: php
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Package php-cli.i386 0:5.1.6-20.el5_2.1 set to be updated
---> 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-gd
--> 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-xml
--> Processing Dependency: php-common = 5.1.6-15.el5 for package: php-soap
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Package php-soap.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Package php-pdo.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Package php-xml.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Package php-gd.i386 0:5.1.6-20.el5_2.1 set to be updated
---> Package php-mysql.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Updating:
 php                     i386       5.1.6-20.el5_2.1  updates           1.1 M
Updating for dependencies:
 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-gd                  i386       5.1.6-20.el5_2.1  updates           113 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
 php-soap                i386       5.1.6-20.el5_2.1  updates           136 k
 php-xml                 i386       5.1.6-20.el5_2.1  updates            94 k

Transaction Summary
=============================================================================
Install      0 Package(s)
Update       8 Package(s)
Remove       0 Package(s)

Total download size: 3.9 M
Is this ok [y/N]:

As you can see it has worked out all the dependencies that need to be updated as well, which include the GD and MySQL PHP packages. After typing in "y" and then <enter> the update starts:

Downloading Packages:
(1/8): php-soap-5.1.6-20. 100% |=========================| 136 kB    00:01
(2/8): php-pdo-5.1.6-20.e 100% |=========================|  62 kB    00:00
(3/8): php-common-5.1.6-2 100% |=========================| 154 kB    00:04
(4/8): php-xml-5.1.6-20.e 100% |=========================|  94 kB    00:01
(5/8): php-gd-5.1.6-20.el 100% |=========================| 113 kB    00:00
(6/8): php-mysql-5.1.6-20 100% |=========================|  84 kB    00:00
(7/8): php-cli-5.1.6-20.e 100% |=========================| 2.1 MB    00:54
(8/8): php-5.1.6-20.el5_2 100% |=========================| 1.1 MB    00:30
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating  : php-common                   ####################### [ 1/16]
  Updating  : php-pdo                      ####################### [ 2/16]
  Updating  : php-cli                      ####################### [ 3/16]
  Updating  : php-soap                     ####################### [ 4/16]
  Updating  : php-xml                      ####################### [ 5/16]
  Updating  : php-gd                       ####################### [ 6/16]
  Updating  : php-mysql                    ####################### [ 7/16]
  Updating  : php                          ####################### [ 8/16]
  Cleanup   : php-soap                     ####################### [ 9/16]
  Cleanup   : php-pdo                      ####################### [10/16]
  Cleanup   : php-common                   ####################### [11/16]
  Cleanup   : php-xml                      ####################### [12/16]
  Cleanup   : php-gd                       ####################### [13/16]
  Cleanup   : php-mysql                    ####################### [14/16]
  Cleanup   : php-cli                      ####################### [15/16]
  Cleanup   : php                          ####################### [16/16]

Updated: php.i386 0:5.1.6-20.el5_2.1
Dependency Updated: php-cli.i386 0:5.1.6-20.el5_2.1 php-common.i386 0:5.1.6-20.el5_2.1 php-gd.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 php-soap.i386 0:5.1.6-20.el5_2.1 php-xml.i386 0:5.1.6-20.el5_2.1
Complete!

And that's it. Easy stuff. All done!




Comments