CentOS 6 has PHP 5.3 in the default repository. I’ve got a request from someone to help him upgrade it’s PHP to 5.4 so here is a quick and lazy way to do it.
Start with your typical CentOS 6 with PHP hosting a bunch of sites all rpms were installed from the default repo:
[root@www ~]# rpm -qa | grep php php-common-5.3.3-40.el6_6.i686 php-5.3.3-40.el6_6.i686 php-process-5.3.3-40.el6_6.i686 php-cli-5.3.3-40.el6_6.i686 php-mysql-5.3.3-40.el6_6.i686 php-mbstring-5.3.3-40.el6_6.i686 php-gd-5.3.3-40.el6_6.i686 php-enchant-5.3.3-40.el6_6.i686 php-pear-1.9.4-4.el6.noarch php-pear-Net-Socket-1.0.10-1.el6.noarch php-pear-Net-SMTP-1.6.1-1.el6.noarch php-IDNA_Convert-0.8.0-1.el6.noarch php-pear-Mail-mimeDecode-1.5.5-1.el6.noarch php-pear-Auth-SASL-1.0.6-1.el6.noarch php-pdo-5.3.3-40.el6_6.i686 php-xml-5.3.3-40.el6_6.i686 php-PHPMailer-5.2.2-1.el6.noarch php-pear-Mail-Mime-1.8.4-1.el6.noarch php-pear-Mail-1.2.0-1.el6.noarch php-simplepie-1.3.1-3.el6.noarch
I’ve got a tip from a friend (thanks wolfy) about the IUS repo. Bonus points, it’s SafeRepo Aware. So let’s add it to the list of repositories:
[root@www ~]# yum -y install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/ius-release-1.0-13.ius.centos6.noarch.rpm Loaded plugins: downloadonly, fastestmirror, priorities Setting up Install Process ius-release-1.0-13.ius.centos6.noarch.rpm | 7.9 kB 00:00 Examining /var/tmp/yum-root-5nBZSW/ius-release-1.0-13.ius.centos6.noarch.rpm: ius-release-1.0-13.ius.centos6.noarch Marking /var/tmp/yum-root-5nBZSW/ius-release-1.0-13.ius.centos6.noarch.rpm to be installed Loading mirror speeds from cached hostfile * base: ftp.ines.lug.ro * epel: fedora.mirrors.telekom.ro * extras: ftp.ines.lug.ro * updates: ftp.ines.lug.ro Resolving Dependencies --> Running transaction check ---> Package ius-release.noarch 0:1.0-13.ius.centos6 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================================================================================================== Installing: ius-release noarch 1.0-13.ius.centos6 /ius-release-1.0-13.ius.centos6.noarch 8.3 k Transaction Summary =================================================================================================================================================================================================================== Install 1 Package(s) Total size: 8.3 k Installed size: 8.3 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : ius-release-1.0-13.ius.centos6.noarch 1/1 Verifying : ius-release-1.0-13.ius.centos6.noarch 1/1 Installed: ius-release.noarch 0:1.0-13.ius.centos6 Complete!
Now we have a bunch of PHP versions we can choose from:
[root@www ~]# yum search php | grep 'cli\.' php-cli.i686 : Command-line interface for PHP php54-cli.i686 : Command-line interface for PHP php55u-cli.i686 : Command-line interface for PHP php56u-cli.i686 : Command-line interface for PHP
There is only one problem. These packages are conflicting with the existing ones, so just “yum install php54” will not work. So we need one more thing:
[root@www ~]# yum -y install yum-plugin-replace Loaded plugins: downloadonly, fastestmirror, priorities Setting up Install Process Loading mirror speeds from cached hostfile * base: ftp.ines.lug.ro * epel: fedora.mirrors.telekom.ro * extras: ftp.ines.lug.ro * ius: download.srv.ro * updates: ftp.ines.lug.ro Resolving Dependencies --> Running transaction check ---> Package yum-plugin-replace.noarch 0:0.2.7-1.ius.centos6 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================================================================================================== Installing: yum-plugin-replace noarch 0.2.7-1.ius.centos6 ius 17 k Transaction Summary =================================================================================================================================================================================================================== Install 1 Package(s) Total download size: 17 k Installed size: 35 k Downloading Packages: yum-plugin-replace-0.2.7-1.ius.centos6.noarch.rpm | 17 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : yum-plugin-replace-0.2.7-1.ius.centos6.noarch 1/1 Verifying : yum-plugin-replace-0.2.7-1.ius.centos6.noarch 1/1 Installed: yum-plugin-replace.noarch 0:0.2.7-1.ius.centos6 Complete!
Now we can just replace the existing packages with:
[root@www ~]# yum -y replace php --replace-with php54 Loaded plugins: downloadonly, fastestmirror, priorities, replace Replacing packages takes time, please be patient... Loading mirror speeds from cached hostfile * base: ftp.ines.lug.ro * epel: fedora.mirrors.telekom.ro * extras: ftp.ines.lug.ro * ius: download.srv.ro * updates: ftp.ines.lug.ro WARNING: Unable to resolve all providers: ['mysql.so', 'mysqli.so', 'pdo_mysql.so', 'curl.so', 'fileinfo.so', 'json.so', 'phar.so', 'php-core', 'php-ereg', 'php-phar', 'php-standard', 'zip.so', 'pdo.so', 'pdo_sqlite.so', 'sqlite3.so', 'config(php)', 'mbstring.so', 'dom.so', 'wddx.so', 'xmlreader.so', 'xmlwriter.so', 'xsl.so', 'gd.so', 'posix.so', 'sysvmsg.so', 'sysvsem.so', 'sysvshm.so', 'enchant.so'] Resolving Dependencies --> Running transaction check ---> Package php.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-cli.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-common.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-enchant.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-gd.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-mbstring.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-mysql.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-pdo.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-pear.noarch 1:1.9.4-4.el6 will be erased ---> Package php-process.i686 0:5.3.3-40.el6_6 will be erased ---> Package php-xml.i686 0:5.3.3-40.el6_6 will be erased ---> Package php54.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-cli.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-common.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-enchant.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-gd.i686 0:5.4.40-1.ius.centos6 will be installed --> Processing Dependency: libt1.so.5 for package: php54-gd-5.4.40-1.ius.centos6.i686 ---> Package php54-mbstring.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-mysql.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-pdo.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-pear.noarch 1:1.9.5-2.ius.centos6 will be installed ---> Package php54-process.i686 0:5.4.40-1.ius.centos6 will be installed ---> Package php54-xml.i686 0:5.4.40-1.ius.centos6 will be installed --> Running transaction check ---> Package t1lib.i686 0:5.1.2-6.el6_2.1 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================================================================================================== Installing: php54 i686 5.4.40-1.ius.centos6 ius 2.7 M php54-cli i686 5.4.40-1.ius.centos6 ius 2.6 M php54-common i686 5.4.40-1.ius.centos6 ius 916 k php54-enchant i686 5.4.40-1.ius.centos6 ius 18 k php54-gd i686 5.4.40-1.ius.centos6 ius 116 k php54-mbstring i686 5.4.40-1.ius.centos6 ius 906 k php54-mysql i686 5.4.40-1.ius.centos6 ius 106 k php54-pdo i686 5.4.40-1.ius.centos6 ius 92 k php54-pear noarch 1:1.9.5-2.ius.centos6 ius 383 k php54-process i686 5.4.40-1.ius.centos6 ius 35 k php54-xml i686 5.4.40-1.ius.centos6 ius 142 k Removing: php i686 5.3.3-40.el6_6 @updates 3.3 M php-cli i686 5.3.3-40.el6_6 @updates 6.3 M php-common i686 5.3.3-40.el6_6 @updates 2.9 M php-enchant i686 5.3.3-40.el6_6 @updates 19 k php-gd i686 5.3.3-40.el6_6 @updates 312 k php-mbstring i686 5.3.3-40.el6_6 @updates 1.9 M php-mysql i686 5.3.3-40.el6_6 @updates 189 k php-pdo i686 5.3.3-40.el6_6 @updates 150 k php-pear noarch 1:1.9.4-4.el6 @base 2.2 M php-process i686 5.3.3-40.el6_6 @updates 53 k php-xml i686 5.3.3-40.el6_6 @updates 275 k Installing for dependencies: t1lib i686 5.1.2-6.el6_2.1 base 152 k Transaction Summary =================================================================================================================================================================================================================== Install 12 Package(s) Remove 11 Package(s) Total download size: 8.1 M Downloading Packages: (1/12): php54-5.4.40-1.ius.centos6.i686.rpm | 2.7 MB 00:00 (2/12): php54-cli-5.4.40-1.ius.centos6.i686.rpm | 2.6 MB 00:00 (3/12): php54-common-5.4.40-1.ius.centos6.i686.rpm | 916 kB 00:00 (4/12): php54-enchant-5.4.40-1.ius.centos6.i686.rpm | 18 kB 00:00 (5/12): php54-gd-5.4.40-1.ius.centos6.i686.rpm | 116 kB 00:00 (6/12): php54-mbstring-5.4.40-1.ius.centos6.i686.rpm | 906 kB 00:00 (7/12): php54-mysql-5.4.40-1.ius.centos6.i686.rpm | 106 kB 00:00 (8/12): php54-pdo-5.4.40-1.ius.centos6.i686.rpm | 92 kB 00:00 (9/12): php54-pear-1.9.5-2.ius.centos6.noarch.rpm | 383 kB 00:00 (10/12): php54-process-5.4.40-1.ius.centos6.i686.rpm | 35 kB 00:00 (11/12): php54-xml-5.4.40-1.ius.centos6.i686.rpm | 142 kB 00:00 (12/12): t1lib-5.1.2-6.el6_2.1.i686.rpm | 152 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 8.2 MB/s | 8.1 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : php54-common-5.4.40-1.ius.centos6.i686 1/23 warning: /etc/php.ini created as /etc/php.ini.rpmnew Installing : php54-cli-5.4.40-1.ius.centos6.i686 2/23 Installing : php54-pdo-5.4.40-1.ius.centos6.i686 3/23 Installing : t1lib-5.1.2-6.el6_2.1.i686 4/23 Installing : php54-gd-5.4.40-1.ius.centos6.i686 5/23 Installing : php54-mysql-5.4.40-1.ius.centos6.i686 6/23 Installing : 1:php54-pear-1.9.5-2.ius.centos6.noarch 7/23 Installing : php54-5.4.40-1.ius.centos6.i686 8/23 Installing : php54-mbstring-5.4.40-1.ius.centos6.i686 9/23 Installing : php54-xml-5.4.40-1.ius.centos6.i686 10/23 Installing : php54-enchant-5.4.40-1.ius.centos6.i686 11/23 Installing : php54-process-5.4.40-1.ius.centos6.i686 12/23 Erasing : php-5.3.3-40.el6_6.i686 13/23 Erasing : php-mysql-5.3.3-40.el6_6.i686 14/23 Erasing : php-pdo-5.3.3-40.el6_6.i686 15/23 Erasing : php-enchant-5.3.3-40.el6_6.i686 16/23 Erasing : php-xml-5.3.3-40.el6_6.i686 17/23 Erasing : php-gd-5.3.3-40.el6_6.i686 18/23 Erasing : php-process-5.3.3-40.el6_6.i686 19/23 Erasing : php-mbstring-5.3.3-40.el6_6.i686 20/23 Erasing : 1:php-pear-1.9.4-4.el6.noarch 21/23 Erasing : php-cli-5.3.3-40.el6_6.i686 22/23 Erasing : php-common-5.3.3-40.el6_6.i686 23/23 Verifying : php54-mbstring-5.4.40-1.ius.centos6.i686 1/23 Verifying : php54-xml-5.4.40-1.ius.centos6.i686 2/23 Verifying : 1:php54-pear-1.9.5-2.ius.centos6.noarch 3/23 Verifying : php54-5.4.40-1.ius.centos6.i686 4/23 Verifying : php54-gd-5.4.40-1.ius.centos6.i686 5/23 Verifying : php54-mysql-5.4.40-1.ius.centos6.i686 6/23 Verifying : php54-pdo-5.4.40-1.ius.centos6.i686 7/23 Verifying : php54-cli-5.4.40-1.ius.centos6.i686 8/23 Verifying : t1lib-5.1.2-6.el6_2.1.i686 9/23 Verifying : php54-common-5.4.40-1.ius.centos6.i686 10/23 Verifying : php54-enchant-5.4.40-1.ius.centos6.i686 11/23 Verifying : php54-process-5.4.40-1.ius.centos6.i686 12/23 Verifying : php-common-5.3.3-40.el6_6.i686 13/23 Verifying : 1:php-pear-1.9.4-4.el6.noarch 14/23 Verifying : php-mysql-5.3.3-40.el6_6.i686 15/23 Verifying : php-mbstring-5.3.3-40.el6_6.i686 16/23 Verifying : php-process-5.3.3-40.el6_6.i686 17/23 Verifying : php-pdo-5.3.3-40.el6_6.i686 18/23 Verifying : php-gd-5.3.3-40.el6_6.i686 19/23 Verifying : php-5.3.3-40.el6_6.i686 20/23 Verifying : php-cli-5.3.3-40.el6_6.i686 21/23 Verifying : php-xml-5.3.3-40.el6_6.i686 22/23 Verifying : php-enchant-5.3.3-40.el6_6.i686 23/23 Removed: php.i686 0:5.3.3-40.el6_6 php-cli.i686 0:5.3.3-40.el6_6 php-common.i686 0:5.3.3-40.el6_6 php-enchant.i686 0:5.3.3-40.el6_6 php-gd.i686 0:5.3.3-40.el6_6 php-mbstring.i686 0:5.3.3-40.el6_6 php-mysql.i686 0:5.3.3-40.el6_6 php-pdo.i686 0:5.3.3-40.el6_6 php-pear.noarch 1:1.9.4-4.el6 php-process.i686 0:5.3.3-40.el6_6 php-xml.i686 0:5.3.3-40.el6_6 Installed: php54.i686 0:5.4.40-1.ius.centos6 php54-cli.i686 0:5.4.40-1.ius.centos6 php54-common.i686 0:5.4.40-1.ius.centos6 php54-enchant.i686 0:5.4.40-1.ius.centos6 php54-gd.i686 0:5.4.40-1.ius.centos6 php54-mbstring.i686 0:5.4.40-1.ius.centos6 php54-mysql.i686 0:5.4.40-1.ius.centos6 php54-pdo.i686 0:5.4.40-1.ius.centos6 php54-pear.noarch 1:1.9.5-2.ius.centos6 php54-process.i686 0:5.4.40-1.ius.centos6 php54-xml.i686 0:5.4.40-1.ius.centos6 Dependency Installed: t1lib.i686 0:5.1.2-6.el6_2.1 Complete!
The install will not replace your php.ini and will just create an php.ini.rpmnew.
Now we can check if the correct version is installed and restart httpd:
[root@www ~]# php -v PHP 5.4.40 (cli) (built: Apr 16 2015 18:43:47) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies [root@www ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@www ~]#
Aaaaand it’s gone done. Enjoy.
If you need so, you can apply the same recipe for php55 or php56.