Linux – How to yum update PHP to version 5.4 on Amazon Linux

amazon ec2linuxPHP

I need PHP 5.4 installed in an Amazon Linux instance.

Presently we have:

root@ip-10-138-1-229 webapps]$ php -version
PHP 5.3.29 (cli) (built: Aug 20 2014 16:41:34)

Is there a yum package for this?

$ yum install php-5.4
Loaded plugins: priorities, security, update-motd, upgrade-helper
Setting up Install Process
No package php-5.4 available.
Error: Nothing to do

Let us try to update yum for php:

yum update php
Dependencies Resolved

===============================================================================================================================================================================
 Package                                   Arch                                 Version                                          Repository                               Size
===============================================================================================================================================================================
Updating:
 php                                       x86_64                               5.3.29-1.7.amzn1                                 amzn-main                               2.8 M
Updating for dependencies:
 php-bcmath                                x86_64                               5.3.29-1.7.amzn1                                 amzn-main                                52 k
 php-cli                                   x86_64                               5.3.29-1.7.amzn1                                 amzn-main                               2.6 M
 php-common                                x86_64                               5.3.29-1.7.amzn1                                 amzn-main                               1.0 M
 php-gd                                    x86_64                               5.3.29-1.7.amzn1                                 amzn-main                               219 k
 php-process                               x86_64                               5.3.29-1.7.amzn1                                 amzn-main                                66 k
 php-xml                                   x86_64                               5.3.29-1.7.amzn1                                 amzn-main                               234 k

Well that’s getting us latest/greatest php 5.3 How to get 5.4?

Maybe PHP 5.4 were not supported yet on Amazon Linux?

UPDATE : slightly updated from @vembutech answer below:

(Run as root):

yum remove httpd*
yum remove $(yum list installed | grep "php" | awk '{print $1}')
yum install httpd24 php54

Now we can use the new nifty builtin httpd server from php 5.4:

root@ip-10-138-1-229 nanoweb_2.2.6]$ php -S localhost:8000
PHP 5.4.37 Development Server started at Fri Feb 20 20:31:22 2015
Listening on http://localhost:8000
Document root is /root/nanoweb_2.2.6
Press Ctrl-C to quit.

Best Answer

First you need to remove the older version and install the new version,

use the below command to remove httpd service.

sudo yum remove httpd*

Get the List of PHP packages installed using the command

sudo yum list installed | grep "php"

Remove Packages

yum remove php-cli.x86_64 php-common.x86_64 php-mysql.x86_64 php-pdo.x86_64 php-xml.x86_64

Now you can install next higher version of httpd and php using yum install command,

sudo yum install httpd24 php54

Related Question